Django 2.0 Tutorial Template

已查看 74 次
跳至第一个未读帖子

Carl Brubaker

未读,
2017年12月9日 16:44:502017/12/9
收件人 Django users
I'm not sure what is wrong, but my template doesn't load correctly. Instead of what I'm supposed to see I get this in my web browser:

<ul>

   

        <li><a href="/polls/1/">What yo?</a></li>

   

    </ul>



Help please!

Dylan Reinhold

未读,
2017年12月9日 16:50:372017/12/9
收件人 django...@googlegroups.com
Show us your template.

Dylan

--
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...@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/5f0061c6-5cf6-4050-98f4-64d52a307d13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carl Brubaker

未读,
2017年12月9日 21:05:552017/12/9
收件人 Django users
I copied it from the django tutorial page:

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}


Dylan Reinhold

未读,
2017年12月9日 23:51:212017/12/9
收件人 django...@googlegroups.com
That looks fine. how about your view.py.

Dylan

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Matthias Müller

未读,
2017年12月10日 05:57:112017/12/10
收件人 django...@googlegroups.com
It look s fine also to me. What do you expect ?

Kavie Mo

未读,
2017年12月10日 09:04:592017/12/10
收件人 Django users
What do you mean by not loading correctly?
is it a problem of your urls.py setting?

Carl Brubaker

未读,
2017年12月10日 15:27:472017/12/10
收件人 Django users
Code for my view.py

from django.shortcuts import render
from django.http import HttpResponse
from django.http import Http404
from django.shortcuts import render
from django.template import loader

from .models import Question

# Create your views here.
def 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)



According to the tutorial, I'm supposed to have: "Load the page by pointing your browser at “/polls/”, and you should see a bulleted-list containing the “What’s up” question from Tutorial 2. The link points to the question’s detail page." which I'm not seeing.

Roberth Solis Martínez

未读,
2017年12月10日 17:52:302017/12/10
收件人 Django users
I think its better if you use:

context = {
        'latest_question_list': latest_question_list,
}

return render(request, 'polls/index.html', context)

Carl Brubaker

未读,
2017年12月10日 18:13:522017/12/10
收件人 Django users
Tried that one too, as it is further down in the tutorial. Still the same result.

Carl Brubaker

未读,
2017年12月10日 18:53:052017/12/10
收件人 Django users
Alright, so I found out the my text editor was saving my files incorrectly. Even though it had ".html" it was displaying the whole text in the web browser, instead of interpreting the the code.
回复全部
回复作者
转发
0 个新帖子