sylvie P
sylvie P

Reputation: 1

DJANGO VIews: how can I add another view already developed to a new one?

I have written a view ("nos_agences" view) in Django which works fine. I would like to add this view to another one in the developing process. The new one includes "nos_agences" view plus other attributes to write.

the existing view

def nos_agences (request):
    """"display nos agences"""
    try:
        agence = Agence.objects.all()
    except Agence.DoesNotExist:
        raise Http404
    return render(request, 'visitor/nos_agences.html', {'agences':agence})

path('nos_agences',views.nos_agences, name= 'nos_agences'),

The new one which must include nos_agences:

def reservation (request):
    return render(request, 'visitor/reservation.html')

Upvotes: 0

Views: 138

Answers (1)

Rezaul Karim Shaon
Rezaul Karim Shaon

Reputation: 145

Use HTTP request method (GET, POST etc.) and in your views.py check the request is GET or POST.

If HTTP request method is GET then call one view, if HTTP request method is POST then call another view.

Upvotes: 1

Related Questions