from django.shortcuts import render
from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)
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)
view.py
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
def hello(request):
return render(request, 'hello.html', {'name':'namenamenamenamename'})
#make sure to keep the templates in the templates folder(you need to make it)
#the name variable is below as you can see
templates/hello.html
<b>fdsfdsfldsjflkdsjkflksja;fdsfdsfldsjflkdsjkflksjasdfkldsjflkdsjfds</b>
{{name}}
<b>>fdlksjfdsljfldsjflkds</b>
from django.http import HttpResponse
from django.template import loader
def my_view(request):
# View code here...
t = loader.get_template('myapp/index.html')
c = {'foo': 'bar'}
return HttpResponse(t.render(c, request), content_type='application/xhtml+xml')