python - django - 重用登录模板

标签 python django authentication

我只是好奇我这样做是否正确。

我正在编写一个网站的私有(private)部分,并编写了一个登录 View ,该 View 会弹出一个登录窗口。我想为几个 url 重用这个 View ,一旦授予访问权限,这些 url 都会转到不同的 View 。看来你不能在 urls.py 的语句中传递参数,所以我给登录 View 一个额外的参数 redirect

def login(request, redirect):
    code to read the login form and parse the POST input
    if POST and loginSuccessful:
        return redirect(request)
    else:
        return render_to_response('login.html', context)

...并使每个特定的 url 都激活一个不同的单行程序,例如 login_to_admin,它只返回带有重定向参数的登录 View 。

def login_to_admin(request):
    return login(request, admin)

def login_to_beta(beta):
    return login(request, beta)

一切正常,我只是想知道这是否是正确的方法。

最佳答案

It doesn't appear that you can pass arguments in the statements in urls.py

You can, actually.

url conf 中的第三项可以是将传递给您的 View 函数的 kwargs 字典。

(r'^my_url/$', 'login', {'redirect': admin}),
(r'^my_other_url/$', 'login', {'redirect': beta}),

关于python - django - 重用登录模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8623101/

相关文章:

python - 使用 openflow 模拟器运行 python 代码

python - Python 词典帮助

django - 为什么 django 强制所有模型类都在 models.py 中?

authentication - 使用用户名和密码的Java LDAP身份验证

php - CakePHP 3 - 多字段身份验证登录

python - hg 使用 fabric 从 bitbucket 中拉出

python - 将行和列总和应用于 Pandas 数据框中的单元格

python - Django admin list_display 属性使用

django - 使用 Django CreateView 处理表单集 - 它不验证

azure - PowerApps 自定义连接器 AADSTS50011 : The reply url specified in the request does not match the reply urls configured for the application