使用Django找不到页面

gum*_*ynr 1 python django

我在我创建的模板文件夹中使用index.html文件设置了我的项目,它在http://example.com上运行正常.当我将welcome.html文件添加到templates文件夹并设置urls.py和views.py文件时,我在http://example.com/welcome.html上收到了一个找不到页面的消息.我已经阅读了许多参考站点进行故障排除但仍无法通过404浏览器页面...

在urls.py中:

from django.conf.urls import patterns,include, url
from django.contrib import admin
from Payments.create import views


urlpatterns = patterns('Payments.create.views',
url(r'^$', 'home', name='home'),
url(r'^/welcome.html$', 'authorization', name='authorization'),
)
Run Code Online (Sandbox Code Playgroud)

在views.py中:

def authorization(request):
    WPdata = request.GET.get('data')
    if WPdata and len(WPdata) > 0:
        content = {'title' : 'My First Post',
            'author' : WPdata,
            'date' : '18th September',
            'body' : ' Lorem ipsum'
        }
    else:
        content = ""

    return render(request,'welcome.html',content) 

def home(request):
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            connection = http.client.HTTPSConnection('api.parse.com', 443)
            connection.connect()
            connection.request('POST', '/1/classes/TestObject', json.dumps({
            "foo": form.cleaned_data['testCode']
            }), {
                 "X-Parse-Application-Id": "xx",
                 "X-Parse-REST-API-Key": "xx",
                 "Content-Type": "application/json"
        })
        results = json.loads(connection.getresponse().read())
    else:
        form = NameForm()

    return render(request,'index.html',{})   
Run Code Online (Sandbox Code Playgroud)

我不确定index.html的设置与预期的工作方式之间的区别是什么,而不是它不会的welcome.html ...我已经为url模式尝试了许多不同的排列并且没有被识别出来任何提供的帮助将不胜感激!

Goc*_*cht 5

你为什么不只用welcome而不是welcome.html?无论如何,试试这个:

url(r'^welcome.html$', 'authorization', name='authorization'),
Run Code Online (Sandbox Code Playgroud)

请注意,我已删除了第一个 '/'