Reputation: 15
I have register view in my django app, that redirects to the homepage:
def register(request):
...register...
return redirect("/")
def homepage(request):
users = User.objects.all().order_by('username')
return render(request, 'index.html', {'users': users})
I want to add variable new_user
that would tell the homepage if user is new. I would pass variable from register view to the homepage view and than into the template where i would handle it:
{% if new_user %}
<h1>Welcome</h1>
{% endif %}
But i dont know how to pass this variable from register view to homepage and than into the template. Help is well appreciated!
Upvotes: 0
Views: 216
Reputation: 648
Try this hope this will help you.
def register(request):
...register...
users = User.objects.all().order_by('username')
return redirect("/", {'users'=users })
def homepage(request,users):
Upvotes: 0
Reputation: 1690
A simple way to achieve that would be to set a parameter in query:
def register(request):
...register...
return redirect('/?new')
def homepage(request):
is_new_user = 'new' in request.GET
....
Upvotes: 1