2013-02-12 136 views
1

django/django/contrib/admin/templates/admin/login.html中,表单的操作路径为{{ app_path }}。这是什么意思?此外,在change_password_form中根本没有行动路径。这个表单如何工作?管理员登录表单django

回答

3

{{ app_path }}是一个模板变量将被替换为从视图传递给它的上下文。在这种情况下,视图是在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的表单。

+0

ahhh它有很多意义。谢谢! – 2013-02-12 07:44:42

+0

@LimH。很高兴清除它:) – 2013-02-12 07:44:59