If no input in search bar it returns me the folowing
The view wish.views.create_wish didn't return an HttpResponse object. It returned None instead.
def create_wish(request):
if request.method == 'POST':
form = WishForm(request.POST)
if form.is_valid():
wish = form.save(commit=False)
wish.author = request.user
wish.save()
my_items = Wish.objects.filter(author=request.user)
all_items = Wish.objects.filter(~Q(author=request.user))
messages.success(request, (
"Your location that you want to "
"visit has been added to List !"))
return render(request, "wish/wish.html", {'all_items': all_items, 'my_items': my_items})
else:
my_items = Wish.objects.filter(author=request.user)
all_items = Wish.objects.filter(~Q(author=request.user))
return render(request, "wish/wish.html", {'all_items': all_items, 'my_items': my_items})
I just want to go back to the page with a message " please enter a place"
CodePudding user response:
Simply you can try this:
def create_wish(request):
if request.method == 'POST':
form = WishForm(request.POST)
if form.is_valid():
wish = form.save(commit=False)
wish.author = request.user
wish.save()
my_items = Wish.objects.filter(author=request.user)
all_items = Wish.objects.filter(~Q(author=request.user))
messages.success(request, (
"Your location that you want to "
"visit has been added to List !"))
return redirect('/home/') #Add your path name here
else:
my_items = Wish.objects.filter(author=request.user)
all_items = Wish.objects.filter(~Q(author=request.user))
return render(request, "wish/wish.html", {'all_items': all_items, 'my_items': my_items})
I have modified this view.
Your above error will solve