使用Djang找不到页面

2024-04-20 01:41:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用一个索引.html我创建的templates文件夹中的文件,它在http://example.com处运行良好。当我加了一个欢迎.html文件到templates文件夹并设置网址.py以及视图.py文件,我在http://example.com/welcome.html收到一条“找不到页面”消息。我已经阅读了一些参考网站的故障排除,但仍然无法通过404浏览器页面。。。你知道吗

在网址.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'),
)

在视图.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',{})   

我不知道这两种设置有什么区别索引.html它按预期工作欢迎.html它不。。。我已经尝试了许多不同的排列方式的网址模式,没有什么是公认的,所以任何提供的帮助将不胜感激!你知道吗


Tags: 文件frompyimportformcomhttpurl
2条回答

使用此选项:

url(r'^welcome.html$', 'authorization', name='authorization')

而不是:

url(r'^/welcome.html$', 'authorization', name='authorization'),

为什么不只用welcome而不用welcome.html?不管怎样,试试这个:

url(r'^welcome.html$', 'authorization', name='authorization'),

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

相关问题 更多 >