嗨我正在尝试让我的工作登录django,但是当我在urls.py中从django转发登录视图并传递我的模板时,我有这样的错误: 在/ login /上的TemplateDoesNotExist 使用引擎django: django.template.loaders.filesystem.Loader:
from django.conf.urls import include,url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'',include('ganagroapp.urls')),
]
模板存在于ganagroapp / templates / ganagroapp
中我的ganagro / urls.py是这样的:
from django.conf.urls import include, url
from . import views
from django.contrib.auth.views import login
app_name = 'ganagroapp'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^product/(?P<pk>[0-9]+)/$', views.product_detail, name='product_detail'),
url(r'^category/(?P<pk>[0-9]+)/$', views.product_category, name='product_category'),
url(r'^product/new/$', views.new_product, name='new_product'),
url(r'^login/$',login,{'template_name':'login.html'}, name='login'),
]
我的ganagroapp / urls.py是这样的:
$('#example').DataTable();
答案 0 :(得分:3)
确保包含django可以找到模板的目录,如下所示:
# your_template_dir_string will depend on where your settings file is in
# relation to this template directory, you'll have to figure that out
# as I can't tell from your linked info
your_template_dir_string = 'ganagroapp/templates/ganagroapp'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# . . .
os.path.join(BASE_DIR, your_template_dir_string),
# . . .
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', #
'social_django.context_processors.login_redirect', #
],
'libraries': {
'content_extras': 'content.templatetags.content_extras',
}
},
},
]
您也可以使用模板加载器,这样您就不必明确指定新的模板目录; app_directories加载程序查找名为&#34; templates&#34;的目录。在已安装的应用中。
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'loaders': [
('django.template.loaders.app_directories.Loader', ),
# you can only specify filesystem loaders like below
# for template directories NOT contained in an installed
# app in django 1.11. For example, a template directory
# contained in your project directory
(
'django.template.loaders.filesystem.Loader',
[os.path.join(BASE_DIR, 'templates')],
),
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends', #
'social_django.context_processors.login_redirect', #
],
'libraries': {
'content_extras': 'content.templatetags.content_extras',
}
},
},
]
答案 1 :(得分:0)
另一种方法是创建一个名为&#39; Registration&#39;在模板内 - &gt; ganagroapp。复制该文件夹中的所有模板。它应该工作。