· 7 years ago · Mar 04, 2018, 08:22 AM
1"""testproject URL Configuration
2
3The `urlpatterns` list routes URLs to views. For more information please see:
4 https://docs.djangoproject.com/en/2.0/topics/http/urls/
5Examples:
6Function views
7 1. Add an import: from my_app import views
8 2. Add a URL to urlpatterns: path('', views.home, name='home')
9Class-based views
10 1. Add an import: from other_app.views import Home
11 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12Including another URLconf
13 1. Import the include() function: from django.urls import include, path
14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15"""
16from django.contrib import admin
17from django.urls import path, re_path
18from test1.views import test1_detail
19
20urlpatterns = [
21 path('admin/', admin.site.urls),
22 re_path('^$', test1_detail)
23]
24
25from django.shortcuts import render
26
27from test1.models import model_test1 as Model
28from django.shortcuts import render
29
30def test1_detail(request):
31
32 tag = Model.objects.get(name__iexact='birlaman')
33 return render(request,
34 'test1/test.html',
35 {'tag':tag})
36
37from django.db import models
38
39
40class model_test1(models.Model):
41
42 name = models.CharField(max_length=31)
43 age = models.TextField()
44
45"""
46Django settings for testproject project.
47
48Generated by 'django-admin startproject' using Django 2.0.1.
49
50For more information on this file, see
51https://docs.djangoproject.com/en/2.0/topics/settings/
52
53For the full list of settings and their values, see
54https://docs.djangoproject.com/en/2.0/ref/settings/
55"""
56
57import os
58
59# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
60BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
61
62
63# Quick-start development settings - unsuitable for production
64# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
65
66# SECURITY WARNING: keep the secret key used in production secret!
67SECRET_KEY = '@i4=#&q%8ib7(oe7h61n5&&t8w89!4jv2#c+r!jk8%cd%)kh$-'
68
69# SECURITY WARNING: don't run with debug turned on in production!
70DEBUG = True
71
72ALLOWED_HOSTS = []
73
74
75# Application definition
76
77INSTALLED_APPS = [
78 'django.contrib.admin',
79 'django.contrib.auth',
80 'django.contrib.contenttypes',
81 'django.contrib.sessions',
82 'django.contrib.messages',
83 'django.contrib.staticfiles',
84 'test1',
85 'test2'
86]
87
88MIDDLEWARE = [
89 'django.middleware.security.SecurityMiddleware',
90 'django.contrib.sessions.middleware.SessionMiddleware',
91 'django.middleware.common.CommonMiddleware',
92 'django.middleware.csrf.CsrfViewMiddleware',
93 'django.contrib.auth.middleware.AuthenticationMiddleware',
94 'django.contrib.messages.middleware.MessageMiddleware',
95 'django.middleware.clickjacking.XFrameOptionsMiddleware',
96]
97
98ROOT_URLCONF = 'testproject.urls'
99
100TEMPLATES = [
101 {
102 'BACKEND': 'django.template.backends.django.DjangoTemplates',
103 'DIRS': [os.path.join(BASE_DIR,'templates')],
104 'APP_DIRS': True,
105 'OPTIONS': {
106 'context_processors': [
107 'django.template.context_processors.debug',
108 'django.template.context_processors.request',
109 'django.contrib.auth.context_processors.auth',
110 'django.contrib.messages.context_processors.messages',
111 ],
112 },
113 },
114]
115
116WSGI_APPLICATION = 'testproject.wsgi.application'
117
118
119# Database
120# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
121
122DATABASES = {
123 'default': {
124 'ENGINE': 'django.db.backends.sqlite3',
125 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
126 }
127}
128
129
130# Password validation
131# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
132
133AUTH_PASSWORD_VALIDATORS = [
134 {
135 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
136 },
137 {
138 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
139 },
140 {
141 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
142 },
143 {
144 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
145 },
146]
147
148
149# Internationalization
150# https://docs.djangoproject.com/en/2.0/topics/i18n/
151
152LANGUAGE_CODE = 'en-us'
153
154TIME_ZONE = 'UTC'
155
156USE_I18N = True
157
158USE_L10N = True
159
160USE_TZ = True
161
162
163# Static files (CSS, JavaScript, Images)
164# https://docs.djangoproject.com/en/2.0/howto/static-files/
165
166STATIC_URL = '/static/'
167
168<!DOCTYPE html>
169
170 <title>
171 <head>Some head title</head>
172 </title>
173
174 <body>
175 {%block context%}
176 Some default content
177 {%endblock%}
178 </body>
179
180</html>
181
182{%extends parent_template|default:"base.html"%}
183
184{%extends parent|default:"test1/base_test1.html"%}
185
186{% block content %}
187 <h1>test succeeded</h1>
188 <p>
189 The tag is: {{tag.name}}
190 </p>
191{% endblock %}
192
193Environment:
194
195
196Request Method: GET
197Request URL: http://127.0.0.1:8000/
198
199Django Version: 2.0.1
200Python Version: 3.5.2
201Installed Applications:
202['django.contrib.admin',
203 'django.contrib.auth',
204 'django.contrib.contenttypes',
205 'django.contrib.sessions',
206 'django.contrib.messages',
207 'django.contrib.staticfiles',
208 'test1',
209 'test2']
210Installed Middleware:
211['django.middleware.security.SecurityMiddleware',
212 'django.contrib.sessions.middleware.SessionMiddleware',
213 'django.middleware.common.CommonMiddleware',
214 'django.middleware.csrf.CsrfViewMiddleware',
215 'django.contrib.auth.middleware.AuthenticationMiddleware',
216 'django.contrib.messages.middleware.MessageMiddleware',
217 'django.middleware.clickjacking.XFrameOptionsMiddleware']
218
219Template loader postmortem
220Django tried loading these templates, in this order:
221
222Using engine django:
223 * django.template.loaders.filesystem.Loader: /home/liz/Documents/testproject/templates/test1/test.html (Source does not exist)
224 * django.template.loaders.app_directories.Loader: /home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/contrib/admin/templates/test1/test.html (Source does not exist)
225 * django.template.loaders.app_directories.Loader: /home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/contrib/auth/templates/test1/test.html (Source does not exist)
226
227
228
229Traceback:
230
231File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
232 35. response = get_response(request)
233
234File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
235 128. response = self.process_exception_by_middleware(e, request)
236
237File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
238 126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
239
240File "/home/liz/Documents/testproject/test1/views.py" in test1_detail
241 11. {'tag':tag})
242
243File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/shortcuts.py" in render
244 36. content = loader.render_to_string(template_name, context, request, using=using)
245
246File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
247 61. template = get_template(template_name, using=using)
248
249File "/home/liz/DocFolder1/DocFolder1/Environments/django2/lib/python3.5/site-packages/django/template/loader.py" in get_template
250 19. raise TemplateDoesNotExist(template_name, chain=chain)
251
252Exception Type: TemplateDoesNotExist at /
253Exception Value: test1/test.html