I the last video, we have added data imputing functionality but data can be duplicated if you click on the save twice. To prevent that, we want to redirect to another page after clicking save.
Import render redirect to allow you the page to be redirected to another after saving the data.
from django.shortcuts import render, redirect
Add return redirect
immediately after form.save()
if form.is_valid():
form.save()
return redirect('/list_items')
having trouble with this it says
TabError: inconsistent use of tabs and spaces in indentation
Make sure you use either space bar or tab and maintain it for that code block. You can highlight the code block to see if the indentations are using the same marks (…. or —-). One of the marks is Spaces and the other Tabs.
IndentationError: unindent does not match any outer indentation level
im using pycharm
Glad you solved it
Im having an error,
File “C:\youtube\venv\src\stockmgmt\views.py”, line 29
return redirect(‘/list_items’)
TabError: inconsistent use of tabs and spaces in indentation
my code is this:
from django.shortcuts import render, redirect
from .models import *
from .forms import StockCreateForm
# Create your views here.
def home(request):
title = ‘Welcome’
context = {
“title” : title
}
return render(request, “home.html”,context)
#query ni siya
def list_items(request):
title = ‘The list of items’
queryset = Stock.objects.all()
context = {
“title” : title,
“queryset”: queryset
}
return render(request, “list_items.html”,context)
def add_items(request):
form = StockCreateForm(request.POST or None)
if form.is_valid():
form.save()
return redirect(‘/list_items’)
context = {
“form”: form,
“title”: “Add Item”,
}
return render(request, “add_items.html”, context)
Great job
its really kinda wierd , i solve it by pressing ctrl+alt and L and indent it again.
its weirdd. cuz the indention at the begining is very similar to urs and still the same. Weird
Great
its really kinda wierd , i solve it by pressing ctrl+alt and L and indent it again.
its weirdd. cuz the indention at the begining is very similar to urs and still the same. Weird v
It might look indented properly but actually not. Using spaces to indent is different from using tabs even when aligned properly to the eye.
im very glad that you reply on my comments. You are great teacher who really helps the beginners.
IndentationError: unindent does not match any outer indentation level
You have a syntax error. Check your code indentation.