我正在尝试覆盖我的Django应用程序中的属性,但是由于某些原因,我不能覆盖LoginView的某些属性。我尝试过将属性作为参数传递给as_view函数,作为我自己的基于类的视图和直接在urlconfig上这样做,但都不起作用。
更具体地说,我试图重写template_name,但Django似乎忽略了我的参数,仍然试图查看“注册/登录.html”,即使我已经在另一个目录中传递了我自己的超文本标记语言模板的另一个路径。我做错了什么?
以下是我的代码,或者我是如何使用它的:
url(r'^accounts/logout/$', auth_views.LogoutView.as_view(template_name='accounts/login.html')),或
class SigninView(LoginView):
template_name = 'login.html'
def get(request):
form = LoginForm
return render(request, self.template_name, {'form':form})我已经尝试更改我的模板名称的名称(或路径),无论是作为as_view函数还是在我创建的基于类的视图上,但Django总是查找这个特定的路径-‘/注册/login.html’-基本上是原始路径。因此,我假设Django出于某种原因无法识别我的覆盖,并查找在LoginView中设置的原始属性。
错误:
TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: GET
Request URL: http://localhost:8000/accounts/login/
Django Version: 1.11.6
Exception Type: TemplateDoesNotExist
Exception Value:
registration/login.html
Request Method: GET
Request URL: http://localhost:8000/accounts/login/...
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/Roi/Desktop/Programming/mysite/home/templates/registration/login.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/admin/templates/registration/login.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/auth/templates/registration/login.html (Source does not exist)
django.template.loaders.app_directories.Loader: /Users/Roi/Desktop/Programming/mysite/home/templates/registration/login.html (Source does not exist)正如你所看到的,我也在我的设置中添加了另一个路径,但django只添加了‘original /login.html’,所以我可以再一次告诉你,不管是什么,我都可以看出它只是使用原始属性……
有什么想法吗?
发布于 2021-05-27 13:31:27
你继承了“views.py”中的“LoginView”,但在“urls.py”中提到了“LogoutView”。您可能没有向我们展示完整的“urls.py”代码。也许你提到的是'LoginView‘而不是'SigninView’。所以'urls.py‘使用'LoginView’来呈现登录页面。
https://stackoverflow.com/questions/46846923
复制相似问题