2013-02-14 82 views
0

我创建一个Django应用程序通过本教程 https://docs.djangoproject.com/en/dev/intro/tutorial04/ 我试图进入管理页面却显示这个错误,我不知道如何解决。Django的错误“中招的SyntaxError同时呈现:无效语法”

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是:34

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}) 

线在这里

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

你能帮帮我!

回答

0
return HttpResponseRedirect(reverse('results', args=p.id)) 
+0

现货,谢谢@尼克 – supersheep1 2013-02-14 03:53:07