development:python:django
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:python:django [2024/08/29 08:05] – [Django Views] tungnt | development:python:django [2024/08/29 08:32] (current) – [Django Views] tungnt | ||
---|---|---|---|
Line 259: | Line 259: | ||
<file python polls/ | <file python polls/ | ||
- | from django.shortcuts import render | + | from django.shortcuts import |
from django.template import loader | from django.template import loader | ||
from django.http import HttpResponse | from django.http import HttpResponse | ||
+ | from django.http import Http404 | ||
from .models import Question | from .models import Question | ||
Line 275: | Line 276: | ||
def detail(request, | def detail(request, | ||
- | try: | + | |
- | question = Question.objects.get(pk=question_id) | + | # |
- | except Question.DoesNotExist: | + | |
- | raise Http404(" | + | # |
+ | |||
+ | question = get_object_or_404(Question, | ||
return render(request, | return render(request, | ||
+ | |||
def results(request, | def results(request, | ||
Line 294: | Line 299: | ||
from . import views | from . import views | ||
+ | |||
+ | app_name = " | ||
urlpatterns = [ | urlpatterns = [ | ||
Line 311: | Line 318: | ||
<ul> | <ul> | ||
{% for question in latest_question_list %} | {% for question in latest_question_list %} | ||
- | < | + | |
+ | < | ||
{% endfor %} | {% endfor %} | ||
</ul> | </ul> | ||
Line 320: | Line 328: | ||
<file html polls/ | <file html polls/ | ||
- | {{ question }} | + | <h1>{{ question.question_text |
+ | < | ||
+ | {% for choice in question.choice_set.all %} | ||
+ | < | ||
+ | {% endfor %} | ||
+ | </ul> | ||
</ | </ | ||
+ | |||
+ | ====== Django Form ====== | ||
+ | |||
+ | https:// | ||
+ |
development/python/django.1724918734.txt.gz · Last modified: 2024/08/29 08:05 by tungnt