Hi Kareem,
On Friday, August 11, 2017 at 8:27:01 PM UTC+2, Kareem Hart wrote:
-- Regarding the 404 page error, you do not have to put a dot (.) at the end of your URL. Django does not have such kind of a pattern match in your urls. 127.0.0.1:8000/polls/ is the correct URL. Having said that, how does your index template look like? It might be that you are getting a blank page because you are not declaring your variables correctly in the template itself. Meaning it might not be specifically a Django back-end error but a front-end html (template) error. Have a look at your template variables and tags and see if your data is correctly being presented to the template. You will need some code like:
{% if latest_question_list %}
{% for question in latest_question_list %} Have a look at the template documentation for details.
On Friday, August 11, 2017 at 8:27:01 PM UTC+2, Kareem Hart wrote:
I am currently up to the "writing views" part of the tutorial and just wrote the polls/index.html template. I updated the view in polls/view.py as such:from django.http import HttpResponsefrom django.template import loaderfrom .models import Questiondef index(request):latest_question_list = Question.objects.order_by('-pub_date')[:5] template = loader.get_template('polls/index.html') context = {'latest_question_list': latest_question_list,}return HttpResponse(template.render(context,request)) def detail(request,question_id):return HttpResponse("You're looking at question %s." % question_id)def results(request,question_id):response = "You're looking at the results of question%s."return HttpResponse(response % question_id)def vote(request,question_id):return HttpResponse("You're voting on question %s." % question_id)I ran $python manage.py check and the system identified no issues.When I open the page 127.0.0.1:8000/polls/ I get a blank page instead of a bulleted list of the questions I created.Also I get the following error when I load 127.0.0.1:8000/polls/.Page not found (404)
Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in
mysite.urls, Django tried these URL patterns, in this order:
- ^polls/
- ^admin/
The empty path didn't match any of these.
mysite.urls
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/305f043f-6f06-4c48-a89b-e9e553da33af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment