I’m trying to redirect to the invoice page but nothing changes except the refresh
this is the url.py
urlpatterns = [
path('', User_login_view, name='login'),
path('home/', HomePageView.as_view(), name='home'),
path("nglm/", NGLMView.as_view() , name="nglm"),
""" other urls for the sidebar"""
path("createinvoice/", NGLINVAPI.as_view(), name="createinvoice"),
path("nglinvoice/", NGLInvoiceTV.as_view(), name="nglinvoice")
]
After login I go to “nglm” page where I input the customer details and click the submit button which calls the api “createinvoice”. the class is shown below
class NGLINVAPI(APIView):
def post(self,request):
if 'nglinv' == request.POST['formtype'] :
data = {
'name': request.data['cname'],
'civilid': request.data['civilid'],
'ph':request.data['ph'],
'disc':request.data['disc'],
'bookno':request.data['Bookno'],
'tga':request.data['LAmount'],
}
p,ccreated = update_customerdb(data=data)
l = update_gldb(data=data)
data['cid'] = p.id
iq,i = update_inventory(data=data,gl=l)
lici = update_LICI(cid=p,lid=l,data=data)
ninv = update_invoice(licid=lici,lid=l,cid=p,data=data,il = iq,items = i)
invid = ninv.id
NGLItemModel.objects.all().delete()
base_url = '/nglinvoice/'
query_string = urlencode({'pk': ninv.pk})
url = '{}?{}'.format(base_url, query_string)
return redirect(url)
return HttpResponseRedirect('home')
this should have redirected me to invoice page “nglinvoice”. the view is show below
class NGLInvoiceTV(TemplateView):
template_name = "pages/nglinvoice.html"
def get(self, request):
p = request.GET['pk']
inv = get_object_or_404(InvoiceModel, pk=p)
context = {}
context['segment'] = 'api'
context['pagename'] = 'New GL API'
context['object'] = inv
return render(request,self.template_name , context)
I have no issues up to this point. the problem is it doesn’t show the page “nglinvoice.html”, it just refresh the “nglm” page
below is what the terminal is showing:
System check identified no issues (0 silenced).
May 15, 2022 - 16:47:28
Django version 3.2.9, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[15/May/2022 16:47:53] "GET / HTTP/1.1" 200 4103
[15/May/2022 16:47:55] "POST / HTTP/1.1" 302 0
[15/May/2022 16:47:55] "GET /home/ HTTP/1.1" 200 23840
[15/May/2022 16:47:58] "GET /nglm/ HTTP/1.1" 200 24028
[15/May/2022 16:47:58] "GET /itemlist/ HTTP/1.1" 200 2
[15/May/2022 16:48:02] "POST /additem/ HTTP/1.1" 302 0
[15/May/2022 16:48:02] "GET /nglm/ HTTP/1.1" 200 24028
[15/May/2022 16:48:02] "GET /itemlist/ HTTP/1.1" 200 2
[15/May/2022 16:48:23] "POST /additem/ HTTP/1.1" 200 8
[15/May/2022 16:48:23] "GET /itemlist/ HTTP/1.1" 200 104
[15/May/2022 16:48:34] "GET /apicheck/?term=p HTTP/1.1" 200 17
[15/May/2022 16:48:35] "GET /get_customerdetails/?k=PETER+JOHNSON&t=n HTTP/1.1" 200 102<br>
[15/May/2022 16:48:38] "POST /createinvoice/ HTTP/1.1" 302 0
[15/May/2022 16:48:38] "GET /nglinvoice/?pk=5 HTTP/1.1" 200 13863
if I enter the last url manually, I can see the page but if i click the submit button it just refresh the page
I also tried using detailview, listview, made a different class, function as well, still same results. I can view the page manually but not from the submit button
how can i go to the invoice page after the clicking the submit button