django - 管理员登录表单 django

标签 django

django/django/contrib/admin/templates/admin/login.html中,表单的action路径为{{ app_path }}。这是什么意思?此外,在 change_password_form 中,根本没有操作路径。表格如何仍然有效?

最佳答案

{{ app_path }} 是一个模板变量,将被从 View 传递给它的上下文替换。在本例中, View 位于 django/contrib/admin/sites.py 中。 :

@never_cache
def login(self, request, extra_context=None):
    """
    Displays the login form for the given HttpRequest.
    """
    from django.contrib.auth.views import login
    context = {
        'title': _('Log in'),
        'app_path': request.get_full_path(),
        REDIRECT_FIELD_NAME: request.get_full_path(),
    }
    context.update(extra_context or {})

    defaults = {
        'extra_context': context,
        'current_app': self.name,
        'authentication_form': self.login_form or AdminAuthenticationForm,
        'template_name': self.login_template or 'admin/login.html',
    }
    return login(request, **defaults)

因此 {{ app_path }} 将被替换为 request.get_full_path() 返回的值,这是请求来自的路径。在本例中,它只是您最初加载表单的 URL。


对于第二个问题,空字符串的操作将表单指向浏览器当前加载的 URL。

关于django - 管理员登录表单 django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14827599/

相关文章:

python - 将数据从数据表传递到模态 django

javascript - 从文本中删除内联样式

python - 强制在 Python 中使用不一致的文件导入路径 (/Django)

django - 如何创建用于测试目的的 django-allauth 常规和社交帐户?

python - 加密和解密 cookie 中的信息

python - 如何使用 perform_create 在 Django Rest Framework 中自动设置字段?

python - Django:django-tables2 更改默认排序行为

django - 如何链接到 django-cms 中未翻译页面的语言主页?

javascript - 更新内容时出错

python - Login_required Django 装饰器