how can i use a button to redirect to admin page?

The names of URLs in Django Admin are of the form:

"admin:<app_label>_<model_name>_change"

(admin is the namespace of the URLs)

So to create a link in a template to go to the “change” page for the User model, which is in the auth app:

<a href="{% url "admin:auth_user_change" user.pk %}">Edit user</a>

Assuming that user is a variable that’s a User object.

And if you wanted to link to the form for adding a new user, you’d use the “add” page instead of the “change” page, and you wouldn’t need user.pk:

<a href="{% url "admin:auth_user_add" %}">Add user</a>
1 Like