我在我的 django 应用程序中添加了一个 tos.html 页面,它在本地运行良好,但是一旦我将其投入生产,它就会显示这一点
NoReverseMatch at /
Reverse for 'tos' not found. 'tos' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://www.flythecoop.io/
Django Version: 2.2.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'tos' not found. 'tos' is not a valid view function or pattern name.
Exception Location: /home/reviews/venv/lib/python3.8/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 673
Python Executable: /home/reviews/venv/bin/python3.8
Python Version: 3.8.0
Python Path:
['/home/reviews/venv/bin',
'/home/reviews/reviews',
'/home/reviews/venv/lib/python38.zip',
'/home/reviews/venv/lib/python3.8',
'/home/reviews/venv/lib/python3.8/lib-dynload',
'/usr/lib/python3.8',
'/home/reviews/venv/lib/python3.8/site-packages']
Server time: Tue, 11 Feb 2020 01:02:33 +0000
它在我的基本.html文件中
63 </body>
64 <footer>
65 <br>
66 <p class="text-center">
67 <a class="btn btn-link btn-sm" href="{% url 'tos' %}" role="button">Terms of Service </a>
68 <a class="btn btn-link btn-sm" href="{% url 'about' %}" role="button">About </a>
69 <a class="btn btn-link btn-sm" href="{% url 'faq' %}" role="button">FAQ </a></p>
70 </footer>
71 </html>
这是我在页面应用程序中 urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.HomePageView.as_view(), name='home'),
path('tos/', views.TosPageView.as_view(), name='tos'),
path('about/', views.AboutPageView.as_view(), name='about'),
path('faq/', views.FaqPageView.as_view(), name='faq'),
]
这是我的 views.py
from django.shortcuts import render
from django.views.generic import TemplateView
# Create your views here.
class HomePageView(TemplateView):
template_name = 'home.html'
class TosPageView(TemplateView):
template_name = 'tos.html'
class AboutPageView(TemplateView):
template_name = 'about.html'
class FaqPageView(TemplateView):
template_name = 'faq.html'
这是项目级别的 urls.py
from django.contrib import admin
from django.urls import path, include
#from boards import views
urlpatterns = [
# This path for pages as static
path('', include('pages.urls')),
path('boards/', include('boards.urls')),
# path('boards/', include('boards.urls')),
path('admin/', admin.site.urls),
path('users/', include('users.urls')),
path('users/', include('django.contrib.auth.urls')),
]
我已经浏览了其他类似的问题,但大多数都是几年前的问题,并且使用不同的版本。我想我一定错过了一些明显的东西,但自从我添加页面以来已经有一段时间了。
修复了它,我只需要为应用程序做sudo supervisorctl restart reviews
,我想它开始为新页面提供服务