我刚刚将Django项目从1.8.5升级到了2.0.6。我可以进入索引页面,但是任何其他链接都可以显示404页面。 enter image description here。有什么问题?预先非常感谢。
这是我urls.py的一部分
from django.conf.urls import *
from django.contrib import admin
from django.contrib.admin.views.decorators import staff_member_required
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^historicalbackground/', views.historicalbackground, name="historicalbackground"),
url(r'^organizations/$', views.organizations, name="Organizations page"),
]
这是views.py
from django.views.generic.base import TemplateView
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import RequestContext, loader, Context
from django.template.loader import get_template
from django.shortcuts import render, render_to_response, redirect
from django.core import management, serializers
from .models import Person, Place, Org, Relationship, Page, Manuscript, PendingTranscription
from html.parser import HTMLParser
from tempfile import *
from .forms import ContactForm, ImportXMLForm, TranscribeForm
from django.core.mail import EmailMessage, send_mail
from django.views.generic import ListView, DetailView
from django.urls import reverse
def historicalbackground (request):
return render(request, 'historicalbackground.html')
def organizations(request):
return render(request, 'organizations.html')
答案 0 :(得分:0)
您可能没有将MIDDLEWARE_CLASSES
更改为MIDDLEWARE
,因此从/historicalbackground
到/historicalbackground/
的重定向无效。有关更多信息,请参见this answer。
从Django 1.8.x升级到2.0.x太大了。您会错过所有弃用警告,因此会出现类似这样的怪异行为。让您的项目在Django 1.11.x上运行而没有过时警告,那么升级到Django 2.0将会更加顺利。