Reputation: 98
Is it possible to create a view/function in django that is callable only from another function I.e. the function doesn't accept any GET
/POST
requests.
Upvotes: 2
Views: 5640
Reputation: 417
You can just call a function in your view as you would normally do, and you can also pass all the arguments you want. It will behave just like a normal function, even though it is called from a view (You can see that the normal function is normal, because it doesn’t return an HttpResponse
object).
from django.shortcuts import render
def example_view(request):
"""Example."""
print_curr_user(request)
return render(request, ‘some_app/some_html.html’)
# Normal function.
def print_curr_user(request):
"""Example: print current user from request object."""
print(request.user)
Upvotes: 1