第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 post 請(qǐng)求找不到 Django 頁(yè)面

使用 post 請(qǐng)求找不到 Django 頁(yè)面

犯罪嫌疑人X 2023-09-19 14:20:13
所以我是 Django 新手,我正在嘗試創(chuàng)建一個(gè) HTML 表單(只需按照名稱輸入教程進(jìn)行操作),我可以輸入名稱,但無(wú)法直接進(jìn)入 /thanks.html 頁(yè)面。$ views.pyfrom django.http import HttpResponseRedirectfrom django.shortcuts import renderfrom .forms import NameFormdef get_name(request):    # if this is a POST request we need to process the form data    if request.method == 'POST':        # create a form instance and populate it with data from the request:        form = NameForm(request.POST)        print(form)        # check whether it's valid:        if form.is_valid():            # process the data in form.cleaned_data as required            # ...            # redirect to a new URL:            return HttpResponseRedirect('/polls/thanks.html')    # if a GET (or any other method) we'll create a blank form    else:        form = NameForm()    return render(request, 'name.html', {'form': form})$ name.html<html>  <form action="/polls/thanks.html" method="post">      {% csrf_token %}      {{ form }}      <input type="submit" value="Submit">  </form><html>$ /mysite/urlsfrom django.contrib import adminfrom django.urls import include, pathurlpatterns = [    path('polls/', include('polls.urls')),    path('admin/', admin.site.urls),]$ mysite/polls/urls.pyfrom django.urls import pathfrom polls import viewsurlpatterns = [    path('', views.get_name, name='index'),]當(dāng)我進(jìn)入該頁(yè)面時(shí),我可以很好地輸入我的名字,但是當(dāng)我提交時(shí),我得到Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:polls/ [name='index']admin/The current path, polls/thanks.html, didn't match any of these.即使thanks.html位于/polls內(nèi)抱歉,如果修復(fù)非常簡(jiǎn)單,我只是以前沒(méi)有使用過(guò) Django。
查看完整描述

2 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

創(chuàng)建一個(gè)視圖,thanks在views.py中調(diào)用


def thanks(request):

    return render(request, 'thanks.html')

現(xiàn)在,通過(guò)添加到投票應(yīng)用程序的 urls.py將/poll/thanks/URL 鏈接到模板。thankspath('thanks/', views.thanks, name='thanks')


$ mysite/polls/urls.py


from django.urls import path


from polls import views


urlpatterns = [

    path('thanks/', views.thanks, name='thanks'),

]

最后在 get_name 視圖中更改以下行


return HttpResponseRedirect('/polls/thanks/')


查看完整回答
反對(duì) 回復(fù) 2023-09-19
?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

改變你的主要urls.py

url(r'^polls/', include('polls.urls')),

在您的應(yīng)用程序中urls.py

url(r'^$', views.get_name, name='index'),

并且在您views.py更改為:

if form.is_valid():
        # process the data in form.cleaned_data as required
        # ...
        # redirect to a new URL:
        return render(request, 'thanks.html')


查看完整回答
反對(duì) 回復(fù) 2023-09-19
  • 2 回答
  • 0 關(guān)注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)