Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template tag on built-in login User.objects.all()

I am using built-in login of django. How I can display all the first name of the registered user on its template using tags?

There's no function to add a context because it is built-in so this is what I added to my urls.py, the kwargs thing what I read to other post.

from django.contrib.auth.models import User

url(r'^login/$', auth_views.login, name='login', kwargs={'all_user': User.objects.all()}),

my template at registration/login.html as default

{% for user in all_user %}
    <option>{{ user.first_name }}</option>
{% endfor %}

When I am accessing now the login it returns an error:

LoginView() received an invalid keyword 'all_user'. as_view only accepts arguments that are already attributes of the class.

Is there a way that I can put the context on built-in login?

like image 437
keisaac Avatar asked Dec 04 '25 08:12

keisaac


1 Answers

url(r'^login/$', auth_views.login, {'extra_context':{'all_user':User.objects.all()}}, name='login'),

use like this

like image 87
Exprator Avatar answered Dec 05 '25 21:12

Exprator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!