【问题标题】:NoReverseMatch at / error on production server, but no issues in localNoReverseMatch at / 生产服务器上的错误,但在本地没有问题
【发布时间】:2020-05-26 09:28:44
【问题描述】:

我在我的 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

在我的 base.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'),
]

这是我的意见.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')),

]

我看过其他类似的问题,但大多数都是几年前的问题,并且使用不同的版本。我想我一定遗漏了一些明显的东西,但是自从我添加页面以来已经有一段时间了。

【问题讨论】:

  • tos 是唯一在 prod 中不起作用的页面吗?或做其他人; aboutfaq有类似问题吗?
  • 两者都有类似的问题,因为我同时添加了这些页面

标签: python django path gunicorn dev-to-production


【解决方案1】:

修复它,我只需要为应用程序执行sudo supervisorctl restart reviews,我猜它开始为新页面提供服务

【讨论】:

    猜你喜欢
    • 2020-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多