【发布时间】:2020-01-10 10:01:01
【问题描述】:
我一直遇到错误信息:
找不到页面 (404) 请求方法:GET 请求 网址:http://127.0.0.1:8000/teachers/app-instructor-billing.html
我知道这通常意味着我没有设置正确配置的 urls.py 来返回定义路径的视图。但是,据我了解,我已经这样做了,但我仍然收到此错误消息
这是我的 urls.py
path('teachers/', include(([
path('', teachers.QuizListView.as_view(), name='app-instructor-dashboard'),
path('logout', teachers.logout_request, name="logout"),
path('edit_user', teachers.edit_user, name='edit_user'),
path('billing', teachers.billing_info, name='app-instructor-billing'),
path('mentor_messages/', teachers.mentor_messages, name='mentor_messages'),
], 'classroom'), namespace='teachers')),
这是我的views.py(teachers.py):
@method_decorator([login_required, teacher_required], name='dispatch')
def billing_info(request):
return render(request, 'classroom/teachers/app-instructor-billing.html')
还有我的html:
<li><a href="{% url 'teachers:billing' %}">Edit Billing</a></li>
【问题讨论】:
-
您的问题是以下网址:127.0.0.1:8000/teachers/app-instructor-billing.html,给出的 404 是否正确?我不明白你为什么认为这是一个错误。您希望该 url 使用什么视图,为什么?
-
@ReinstateMonica 我在我的 html 中单击编辑计费,urls.py 然后找到教师:计费的对应视图,即教师.billing_info。然后呈现在我的 billing_info 函数中返回的 html,或者我错过了什么?这适用于我拥有的其他网址
-
对不起,我误会了。我现在看到你的问题了。您在 url 标记中使用了错误的命名空间。它应该是
teachers:app-instructor-billing而不是teachers:billing -
@ReinstateMonica 收到此错误消息现在引发 NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Reverse for 'app-instructor-billing' not found。 'app-instructor-billing' 不是有效的视图函数或模式名称。
-
urls.py所在的应用程序名称是什么?还是在您的根项目文件夹中?