I'm using Django forms to handle user input for some point on my Django app. but it keeps showing this error whenever the user tries to submit the form.
ValueError: The view *my view name goes here* didn't return an HttpResponse object. It returned None instead
Here's the code:
Forms.py
class sendBreachForm(forms.Form):"""Form for sending messages to users."""text = forms.CharField(max_length=100)image = forms.FileField()cords = forms.CharField(widget=forms.TextInput(attrs={"type":"hidden"}))
views.py
@login_required
def web_app(request):if request.user.is_staff or request.user.is_superuser:return redirect('/ar/system/')else:if request.method == "POST":form = sendBreachForm(request.POST)print("AAAAAAAAa in a post request")if form.is_valid():print("AAAAAAAAa form is valid")text = form.cleaned_data['text']image = form.cleaned_data['image']cords = form.cleaned_data['cords']try:new_breach = Breach.object.create(text=text,image=image)add_form_cords_to_breach(request,new_breach,cords) print("AAAAAAAA added breach")return render(request,"web_app.html",context) except :print("AAAAAAAA error ")return render(request,"web_app.html",context) # raise Http404('wrong data')else:form = sendBreachForm()context = {}context['form']=formcontext['all_elements'] = WaterElement.objects.all()current_site = Site.objects.get_current()the_domain = current_site.domaincontext['domain'] = the_domainall_layers = MapLayers.objects.all()context['all_layers']=all_layersreturn render(request,"web_app.html",context)
HTML
<form method ='post'>{% csrf_token %}{{form.text}}<label for="text">وصف المعاينة</label>{{form.image}}<label for="image">صورة المعاينة</label>{{form.cords}}<input type="submit" value = "إرسال المعاينة"></form>