In template /Users/wei/learning_logs/templates/learning_logs/base.html, error at line 0

2019-01-09 15:33:39 +08:00
 greatchenny
新手,调了一天了,还是没解决,请求大佬支援

报错内容
NoReverseMatch at /users/login/
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8000/users/login/
Django Version: 2.1.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.
Exception Location: /Users/wei/anaconda3/envs/opp/lib/python3.6/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 622
Python Executable: /Users/wei/anaconda3/envs/opp/bin/python
Python Version: 3.6.7
Python Path:
['/Users/wei',
'/Users/wei/anaconda3/envs/opp/lib/python36.zip',
'/Users/wei/anaconda3/envs/opp/lib/python3.6',
'/Users/wei/anaconda3/envs/opp/lib/python3.6/lib-dynload',
'/Users/wei/anaconda3/envs/opp/lib/python3.6/site-packages']
Server time: Wed, 9 Jan 2019 07:30:40 +0000


login.html

{% extends "learning_logs/base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form action="{% url 'users:login' %}" method='post'>
{% csrf_token %}
{{ form.as_p }}
<button name="submit">log in</button>
<input type="hidden" name="next" value="{% url 'learning_logs:index' %}" />
</form>
<p>AAAAAAA</p>
{% endblock content %}



urls.py

from django.urls import path, re_path
from django.contrib.auth import views as auth_views
app_name = 'users'
urlpatterns = [
# 登录页面
# path('users/', auth_views.LoginView.as_view(template_name='users/login.html')),
path('users/login/', auth_views.LoginView.as_view(template_name='users/login.html')),
]
2130 次点击
所在节点    Python
4 条回复
chenstack
2019-01-09 19:26:56 +08:00
django 的 url 反查要在注册时给出 name 参数
path('users/login/', auth_views.LoginView.as_view(template_name='users/login.html'), name="login"),
另外表单提交到当前 url 可以不写 form 标签的 action 参数
greatchenny
2019-01-09 20:35:23 +08:00
@chenstack 新手,可以直接写代码怎么改,
greatchenny
2019-01-09 20:40:49 +08:00
@greatchenny 看到了,添加了个 name 参数果然好了,
greatchenny
2019-01-09 20:58:24 +08:00
@chenstack 大牛能加个 V 信不,以后有什么不懂可以微信上问你、

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/525399

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX