I have 2 functions in my django views.py file, which are giving me problems. Django is showing that there is a syntax error at the else lines, but I can’t see any problem near it.(All required functions etc are imported)
I would like some help with this
@login_required
def add_post(request, forumslug, threadslug):
if request.method=='POST':
form = PostForm(request.POST)
if form.is_valid():
user = request.user
title = form.cleaned_data['title']
body = form.closed_data['body']
thread = get_object_or_404(Thread, slug=threadslug)
forum = get_object_or_404(Forum, slug=forumslug)
post = Post.objects.create(title=title, body=body, creator=user, thread=thread)
url = '/%s/%s/' % (forumslug, slugify(title))
return HttpResponseRedirect(url)
else:
form = PostForm()
variables = RequestContext(request, {'form': form})
return render_to_response('forum/new_post.html', variables)
@login_required
def add_thread(request, forumslug):
if request.method=="POST":
form = PostForm(request.POST)
if form.is_valid():
user = request.user
forum = get_object_or_404(Forum, slug=forumslug)
title = form.cleaned_data['title']
body = form.cleaned_data['body']
thread = Thread.objects.create(title=title, slug=slugify(title), forum=forum, creator=user, body=body)
url = '/%s/%s' % (forumslug, slugify(title))
return HttpResponseRedirect(url)
else:
form = PostForm()
variables = RequestConext(request, {'form': form})
return render_to_response('forum/new_thread.html', variables)
The line
url = '/%s/%s/' % (forumslug, slugify(title)is actually missing a closing bracket, sure the error is not raised for the line that is above theelseone?