Hey everybody, thank you for clicking on my post. Any sort of help is appreciated
I have an issue with the API when the POST request isn’t getting successful.
This is my views.py page,
from django.shortcuts import render
from django.http import JsonResponse
from django.apps import apps
from ssr.forms import InputForm
from django.views.decorators.csrf import csrf_exempt
import json
def home(request):
return render(request, 'index.html', {'title': 'Home', 'message': 'Welcome to the homepage!'})
def index(request):
return render(request, 'index.html')
def analysis(request):
return render(request, 'analysis.html')
def contact(request):
return render(request, 'contact.html')
def documentation(request):
return render(request, 'documentation.html')
def gallery(request):
return render(request, 'gallery.html')
def result(request):
form = InputForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
ssr_type = form.cleaned_data['ssrtype']
chromosome = form.cleaned_data['chromosome']
start = form.cleaned_data['start']
end = form.cleaned_data['end']
try:
model_class = apps.get_model('ssr', ssr_type.lower() + 's')
objects = model_class.objects.filter(
Chromosome=chromosome,
Start__gte=start,
End__lte=end
).values('ID', 'Chromosome', 'SSRtype', 'SSRsequence', 'Size', 'Start', 'End')
context = {
'objects': list(objects),
'form': form
}
return render(request, 'result.html', context)
except LookupError:
form.add_error(None, 'The specified SSR model does not exist!')
except Exception as e:
form.add_error(None, 'The specified SSR model does not exist!')
return render(request, 'result.html', {'form': form})