【发布时间】:2020-04-18 22:44:34
【问题描述】:
我有项目的 urls.py 文件,它位于 forecast/urls 里面我正在尝试为我的应用程序的 url 设置 url 路由
from django.contrib import admin
from django.urls import path,include
from django.contrib.auth import login
urlpatterns = [
path('auth/',include
('authorization.urls')),
]
在authorization/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('login/',
views.login_name),
]
运行服务器后我想打开http://127.0.0.1:8000/auth/login/,我得到了
NoReverseMatch at/
auth/login/
Reverse for 'login' not found. 'login' is
not a valid view function or pattern
name.
根据我的 url 设置,我希望项目 urls.py 中的路径函数将提供给包含的授权/urls.py 路径 auth/,而不是来自 authorization/urls.py 的第二条路径将添加到它的模式 login 而不是构造 @987654330如果我是对的,@ 会给我的视图函数,为什么我得到 NoReverse 错误。谁能指导我做错了什么
我的完整追溯在这里
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.Request Method:GETRequest URL:http://127.0.0.1:8000/auth/login/Django Version:2.2.4Exception Type:NoReverseMatchException Value:Reverse for 'login' not found. 'login' is not a valid view function or pattern name.Exception Location:/data/data/com.termux/files/home/storage/predictions/env/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 668Python Executable:/data/data/com.termux/files/home/storage/predictions/env/bin/pythonPython Version:3.7.4Python Path:['/data/data/com.termux/files/home/storage/predictions/forecast', '/data/data/com.termux/files/home/storage/predictions/forecast', '/data/data/com.termux/files/home/storage/predictions/env/lib/python37.zip', '/data/data/com.termux/files/home/storage/predictions/env/lib/python3.7', '/data/data/com.termux/files/home/storage/predictions/env/lib/python3.7/lib-dynload', '/data/data/com.termux/files/usr/lib/python3.7', '/data/data/com.termux/files/home/storage/predictions/env/lib/python3.7/site-packages']Server time:Mon, 30 Dec 2019 06:58:18 +0000
【问题讨论】:
标签: django python-3.x django-urls