hi guys i am having trouble in finding the syntax error in my Django views.I am trying to create the view of creating a post by a user with the help of inline formset as code given below.But the view is throwing error in case of following below:
iam getting the error indicator right below the (:)
if request.method == 'POST':
SyntaxError: invalid syntax
I checked the indentations but can't spot the error spot.can you find it out if you are reading it ?
#views.py
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render
from . import forms
from .models import *
@login_required
def post(request):
form = forms.PostForm()
formset =forms.AnswerInlineFormSet(queryset=models.Answer.objects.none()
if request.method == 'POST':
form = forms.PostForm(request.POST)
formset=forms.ImageInlineFormSet(request.POST,request.
FILES,queryset=Images.objects.none())
if form.is_valid() and formset.is_valid():
post = form.save(commit=False)
post.user = request.user
post.save()
images = formset.save(commit=False)
for image in images:
image.post = post
image.save()
messages.success(request,'Post added.')
return HttpResponseRedirect('/feeds')
return render(request,'usersubmit/post_create.html',{'form'= form,'formset' = formset,})
here is the form for the view:
#forms.py
from django import forms
from .models import Post,Images
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ('title', 'synopsis','category','tags' )
class ImageForm(forms.ModelForm):
class Meta:
model = Images
fields = ('image','body', )
ImageFormset= forms.modelformset_factory(
models.Images,
form=ImageForm,
)
ImageInlineFormSet = forms.inlineformset_factory(
models.Post,
models.Images,
extra=2,
fields = ('image','body', ),
formset=ImageFormset,
min_num=1,
)
can you guys please review my code?
need add
)
to