简体   繁体   中英

Django input login for an admin

How can I add attribute autocomplete="off" to the input login template form for an admin?

I'm find this in the login.html template but can't find where is the form template

<div class="form-row">
    {{ form.username.errors }}
    {{ form.username.label_tag }} {{ form.username }}
</div>

If you need to change behavior based on whether or not the user is admin/staff:

{% if request.user.is_staff %}
    <form autocomplete="off" method="post" action="action_name">
        <input autocomplete="off" name="hidden" type="text" style="display:none;">
{% else %}
    <form method="post" action="action_name">
{% endif %}
    <div class="form-row">

And complete the rest of the form as you would. Reference for the form and input tags to turn autocomplete off (note autocomplete is "off" in the input tag as per testing in comments): https://gist.github.com/niksumeiko/360164708c3b326bd1c8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM