V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
greatchenny
V2EX  ›  Python

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

  •  
  •   greatchenny · 2019-01-09 15:33:39 +08:00 · 2111 次点击
    这是一个创建于 2144 天前的主题,其中的信息可能已经有所发展或是发生改变。
    新手,调了一天了,还是没解决,请求大佬支援

    报错内容
    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')),
    ]
    4 条回复    2019-01-09 20:58:24 +08:00
    chenstack
        1
    chenstack  
       2019-01-09 19:26:56 +08:00   ❤️ 1
    django 的 url 反查要在注册时给出 name 参数
    path('users/login/', auth_views.LoginView.as_view(template_name='users/login.html'), name="login"),
    另外表单提交到当前 url 可以不写 form 标签的 action 参数
    greatchenny
        2
    greatchenny  
    OP
       2019-01-09 20:35:23 +08:00
    @chenstack 新手,可以直接写代码怎么改,
    greatchenny
        3
    greatchenny  
    OP
       2019-01-09 20:40:49 +08:00
    @greatchenny 看到了,添加了个 name 参数果然好了,
    greatchenny
        4
    greatchenny  
    OP
       2019-01-09 20:58:24 +08:00
    @chenstack 大牛能加个 V 信不,以后有什么不懂可以微信上问你、
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2728 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:53 · PVG 22:53 · LAX 06:53 · JFK 09:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.