标签:cts latest tail _id model att data- result logs
def detail(request, question_id):
returnHttpResponse("You‘re looking at question %s."% question_id)
def results(request, question_id):
response ="You‘re looking at the results of question %s."
returnHttpResponse(response % question_id)
def vote(request, question_id):
returnHttpResponse("You‘re voting on question %s."% question_id)
from django.conf.urls import url
from.import views
urlpatterns =[
# ex: /polls/
url(r‘^$‘, views.index, name=‘index‘),
# ex: /polls/5/
url(r‘^(?P<question_id>[0-9]+)/$‘, views.detail, name=‘detail‘),
# ex: /polls/5/results/
url(r‘^(?P<question_id>[0-9]+)/results/$‘, views.results, name=‘results‘),
# ex: /polls/5/vote/
url(r‘^(?P<question_id>[0-9]+)/vote/$‘, views.vote, name=‘vote‘),
]
from django.http importHttpResponse
from.models importQuestion
def index(request):
latest_question_list =Question.objects.order_by(‘-pub_date‘)[:5]
output =‘, ‘.join([q.question_text for q in latest_question_list])
returnHttpResponse(output)
{%if latest_question_list %}
<ul>
{%for question in latest_question_list %}
<li><a href="/demo/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{%else%}
<p>No polls are available.</p>
{% endif %}
from django.http importHttpResponse
from django.template import loader
from.models importQuestion
def index(request):
latest_question_list =Question.objects.order_by(‘-pub_date‘)[:5]
template = loader.get_template(‘demo/index.html‘)
context ={
‘latest_question_list‘: latest_question_list,
}
returnHttpResponse(template.render(context, request))
from django.shortcuts import render
from.models importQuestion
def index(request):
latest_question_list =Question.objects.order_by(‘-pub_date‘)[:5]
context ={‘latest_question_list‘: latest_question_list}
return render(request,‘demo/index.html‘, context)
from django.http importHttp404
from django.shortcuts import render
from.models importQuestion
# ...
def detail(request, question_id):
try:
question =Question.objects.get(pk=question_id)
exceptQuestion.DoesNotExist:
raiseHttp404("Question does not exist")
return render(request,‘demo/detail.html‘,{‘question‘: question})
from django.shortcuts import get_object_or_404, render
from.models importQuestion
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request,‘demo/detail.html‘,{‘question‘: question})
<h1>{{ question.question_text }}</h1>
<ul>
{%for choice in question.choice_set.all %}
<li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>
<li><a href="/demo/{{ question.id }}/">{{ question.question_text }}</a></li>
<li><a href="{% url ‘detail‘ question.id %}">{{ question.question_text }}</a></li>
...
# the ‘name‘ value as called by the {% url %} template tag
url(r‘^(?P<question_id>[0-9]+)/$‘, views.detail, name=‘detail‘),
...
...
# added the word ‘specifics‘
url(r‘^specifics/(?P<question_id>[0-9]+)/$‘, views.detail, name=‘detail‘),
...
from django.conf.urls import url
from.import views
app_name =‘demo‘
urlpatterns =[
url(r‘^$‘, views.index, name=‘index‘),
url(r‘^(?P<question_id>[0-9]+)/$‘, views.detail, name=‘detail‘),
url(r‘^(?P<question_id>[0-9]+)/results/$‘, views.results, name=‘results‘),
url(r‘^(?P<question_id>[0-9]+)/vote/$‘, views.vote, name=‘vote‘),
]
<li><a href="{% url ‘detail‘ question.id %}">{{ question.question_text }}</a></li>
<li><a href="{% url ‘demo:detail‘ question.id %}">{{ question.question_text }}</a></li>
标签:cts latest tail _id model att data- result logs
原文地址:http://www.cnblogs.com/leejy/p/6745194.html