Django:Django 的视图问题django-注册 +金贾
所以,我有一个使用 jinja2 渲染的 django 项目,并且我还安装了 django-registration 以使我的生活更轻松。我遇到了以下问题:
转到主页我用 jinja 渲染它。为了检查身份验证,我必须使用 jinja 的语法,即 user.is_authenticated()。然而,在常规 django 模板中,此检查是通过 user.is_authenticated 完成的。如果在常规 django 模板中有 (),则会出错。
因此,进入 /accounts/login/ 页面,django-registration 模块没有做任何特殊的事情,因此它将 url 按以下方式转发到标准 django 视图:
from django.contrib.auth import views as auth_views
url(r'^login/$',
auth_views.login,
{'template_name': 'registration/login.html'},
name='auth_login'),
所以我确信我不应该更改 django .contrib.auth 视图,但是我该把自己的视图放在哪里呢?在 myapp/views.py 中?
另外,我是否必须复制粘贴 django 视图,然后在其之上进行修改(在本例中只需将渲染替换为 render_jinja),或者有没有办法将这个原始 django 视图“扩展”为我自己稍微修改过的视图用于登录?
So, I have a django project that is using jinja2 rendering, and I also installed django-registration to make my life easier. I ran into the following problem:
Going to homepage I render it with jinja. In order to check for authentication, I have to use jinja's syntax, which is user.is_authenticated(). However, in regular django templating, this check is done with user.is_authenticated. If in regular django templating there are (), it gives error.
So going to the /accounts/login/ page, the django-registration modul doesn't do anything special, so it forwards the url to the standard django views the following way:
from django.contrib.auth import views as auth_views
url(r'^login/
So I know for sure I shouldn't be changing the django.contrib.auth view, but then where do i put my own view? In myapp/views.py?
And also, do I have to copy paste the django view, and then modify on top of it (in this case simply replace the render with render_jinja) or is there a way to 'extend' this original django view to my own slightly modified view for logging in?
,
auth_views.login,
{'template_name': 'registration/login.html'},
name='auth_login'),
So I know for sure I shouldn't be changing the django.contrib.auth view, but then where do i put my own view? In myapp/views.py?
And also, do I have to copy paste the django view, and then modify on top of it (in this case simply replace the render with render_jinja) or is there a way to 'extend' this original django view to my own slightly modified view for logging in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论正确还是错误,在注册模块中,我创建了一个新视图,用于处理日志记录,从各处复制几行。这是合乎逻辑的,而且似乎工作得很好。
Whether right or wrong, in the registration module, I made a new view, that handled the logging, copying a few lines from here and there. It logical and seems to be working fine.