5👍
✅
You are redirecting if form.is_valid()
but what about the form is invalid? There isn’t any code that get’s executed in this case? There’s no code for that. When a function doesn’t explicitly return a value, a caller that expects a return value is given None
. Hence the error.
You could try something like this:
def edit(request, row_id):
rating = get_object_or_404(Rating, pk=row_id)
context = {'form': rating}
if request.method == "POST":
form = RatingForm(request.POST)
if form.is_valid():
form.save()
return redirect('home.html')
else :
return render(request, 'ratings/entry_def.html',
{'form': form})
else:
return render(
request,
'ratings/entry_def.html',
context
)
This will result in the form being displayed again to the user and if you have coded your template correctly it will show which fields are invalid.
👤e4c5
- [Django]-Add reply to address to django EmailMultiAlternatives
- [Django]-Create HTML Mail with inline Image and PDF Attachment
- [Django]-Django Authenticate Backend Multiple Databases
- [Django]-Django autocomplete_fields doesn't work in TabularInline (but works in StackedInline)
- [Django]-In stripe checkout page display Country or region fields how to remove it
0👍
your error to the indentation of a Python file. You have to be careful when following tutorials and/or copy-pasting code. Incorrect indentation can waste lot of valuable time.
- [Django]-MySQL database being hit too many times with django query
- [Django]-Django extends different base templates
- [Django]-How to extend UserCreationForm with fields from UserProfile
0👍
You Should Return What file you are rendering instead of Direct Render.
def index(request):
return render(request, 'index.html')
def login(request):
return render(request,'login.html')
def logout(request):
return render(request,'index.html')
- [Django]-Django filtering QueryString by MultiSelectField values?
- [Django]-Crispy-forms InlineRadios don't show my model state
- [Django]-Multi-table inheritance in the admin view
- [Django]-How add tag to pandas dataframe.to_html links so that absolute path of url will not shown in the html but a tag instead?
Source:stackexchange.com