0

我正在通过本教程创建一个 django 应用程序 https://docs.djangoproject.com/en/dev/intro/tutorial04/ 我正在尝试访问管理页面,但它显示了这个我不知道如何修复的错误.

TemplateSyntaxError at /admin/
Caught SyntaxError while rendering: invalid syntax (views.py, line 34)Request Method: GET 
Request URL: http://cat.pythonanywhere.com/admin/ 
Django Version: 1.3.5 
Exception Type: TemplateSyntaxError 
Exception Value: Caught SyntaxError while rendering: invalid syntax (views.py, line 34) 
Exception Location: /home/cat/mysite/myapp/urls.py in <module>, line 2 
Python Executable: /usr/local/bin/uwsgi 
 Python Version: 2.7.3 
Python Path: ['/var/www',

我的views.py是:

from django.http import HttpResponse ,HttpResponseRedirect
from mysite.myapp.models import Poll
from django.http import Http404
from django.template import Context, loader
from django.shortcuts import render, get_object_or_404
from django.core.urlresolvers import reverse
from polls.models import Choice, Poll

def index(request):
    return HttpResponse("Hello, world. You're at the poll index.")

def detail(request, poll_id):
    return HttpResponse("You're looking at poll %s." % poll_id)

def results(request, poll_id):
    return HttpResponse("You're looking at the results of poll %s." % poll_id)

def vote(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the poll voting form.
        return render(request, 'myapp/detail.html', {
            'poll': p,
            'error_message': "You didn't select a choice.",
        })
    else:
        selected_choice.votes += 1
        selected_choice.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('myapp:results', args=(p.id,))))


def index(request):
    latest_poll_list = Poll.objects.order_by('-pub_date')[:5]
    template = loader.get_template('myapp/index.html')
    context = Context({
    'latest_poll_list': latest_poll_list,
    })
    return HttpResponse(template.render(context))



def detail(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    return render(request, 'myapp/detail.html', {'poll': poll})
def results(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    return render(request, 'myapp/results.html', {'poll': poll})   

第 34 行在这里

        return HttpResponseRedirect(reverse('myapp:results', args=(p.id,))))

你能帮我么!

4

1 回答 1

0
    return HttpResponseRedirect(reverse('results', args=p.id))
于 2013-02-14T03:46:53.687 回答