Home > other >  Consult a strange problem in django
Consult a strange problem in django

Time:10-04


File structure as shown above, using regular expressions r '^ $' url (r' ^ $' views. The index name='index'), cannot open the localhost: 8000, polls, the index page, and change to the
Url (' 'views. The index name=' index ') is ok, what reason is this excuse me? And the url is must be on the bottom, if upon several other url,
Open the index, and then open the other pages are shown the index page, ask ace to give directions, this is how to return a responsibility?
Polls \ urls py
The from the django. Contrib import admin
The from the django. Urls import path
The from the django. Conf. Urls import url
The from mysite import view
From the import views
Urlpatterns=[
# path (' 'views. Polls),
# the ex:/polls,
# the ex:/polls/5/
The url (r '^ (? P# the ex:/polls/5/results/
The url (r '^ (? P# the ex:/polls/5/vote/
The url (r '^ (? PUrl (r '^ $' views. The index, name=' index '),
]

Polls \ views. Py
The from the django. Shortcuts import render
The from the django. HTTP import HttpResponse
. From the django template import loader
The from the django. HTTP import Http404
# the Create your views here.
From the models the import Question

Def index (request) :
Latest_question_list=Question. Objects. Order_by (' - pub_date) [5]
The template=loader. Get_template (' polls/index. HTML ')
The context={
'latest_question_list: latest_question_list,
}
=', '# output. Join ([q.q uestion_text for q in latest_question_list])
Return render (request, 'polls/index. HTML, context)
.

CodePudding user response:

Oh, the original here cannot enter localhost: 8000/polls/index, and to enter localhost: 8000/polls, if must add index, you must put the r '^ $', to r', and put the url in the back, don't know what reason
  • Related