什么/哪里修改django注册使用手机的兄弟 [英] What/Where to modify django-registration to use with mobile broswers

查看:167
本文介绍了什么/哪里修改django注册使用手机的兄弟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django注册沿着django身份验证我的客户帐户创建和登录。

I am using django-registration along side django auth for my client account creation and login.

我们的网站将被moble用户和桌面用户使用。通过根据用户代理字符串从视图中加载不同的模板,我们刚开始处理移动用户的想法。这是干净的,但我不知道这是否是正确的方法,因为我们现在坚持在不容易访问的视图(我们没有写自己)做什么。

Our site will be used by moble users and desktop users. We just started tackling the idea of mobile users by loading different templates from the view depending on user agent strings. It's cleanly done, but I am not sure if it is the right way to do it as we are now stuck with what to do on views that are not easily accessible (that we didn't write ourselves).

这给我带来了现在的问题:
我不知道如何解决将移动用户重定向到远程登录到django-registration / auth将其发送到的桌面(桌面版本)。

Which brings me to the problem at hand: I have no idea how to tackle redirecting the mobile user away from the login url that django-registration/auth sends them to (the desktop version).

我可以改变策略,解决模板文件本身的不同浏览器。那感觉就像是快一点乱七八糟。我不喜欢这个想法!

I could change tactics and tackle the different browsers in the template files themselves. That feels like it is going to get messy fast. I don't like that idea at all!

或者我留下我目前的方法,这是根据用户代理字符串呈现不同模板的请求。然后我需要知道如何处理django注册(如何根据用户代理字符串加载一组不同的模板)。我宁愿不要更改django注册码,只是为了使更新模块更容易。

Or I stay with my current method, which is to render the request with different templates based on user agent strings. Then i need to know how I should be dealing with django-registration (how to load a different set of templates based on the user agent string). I would rather not change the django-registration code, if just to make updating modules easier.

推荐答案

django注册模板非常简单,很少使用。我简单地处理这些作为特殊情况,只是想出了一个base.html,在两个平台上运行得很好。

The django registration templates are very simple and are used very rarely. I simply handle these as special cases and just come up with a base.html for that works on both platforms reasonably well.

我的注册页面看起来很简单,许多网站做这并不意外。

My registration pages look very simple, many sites do this and it is not unexpected.

另一个选择是我们一个中间件,它根据检测是否是移动设备来设置模板目录。您可以像这样检测移动浏览器检测移动浏览器(不只是iPhone)在python视图,然后有一个中间件使用make_tls_property技巧来更新TEMPLATE_DIRS这样的东西:

Another option is to us a middleware which sets the template directory based upon detecting if it is a mobile device. You can detect the mobile browser like this Detect mobile browser (not just iPhone) in python view and then have a middleware that uses the make_tls_property trick to update the TEMPLATE_DIRS something like this:

TEMPLATE_DIRS = settings.__dict__['_wrapped'].__class__.TEMPLATE_DIRS = make_tls_property(settings.TEMPLATE_DIRS)

class MobileMiddleware(object):
    """Sets settings.SITE_ID based on request's domain"""
    def process_request(self, request):
        if *mobile*:
            TEMPLATE_DIRS.value = *mobiletemplates* + settings.BASE_TEMPLATE_DIRS
        else:
            TEMPLATE_DIRS.value = *normaltemplates* + settings.BASE_TEMPLATE_DIRS

只是为了清楚,make_tls_property,这是一部分的djangotoolbox,使TEMPLATE_DIRS设置一个每个线程的变量代替一个全局变量,所以每个请求响应循环都得到它自己的version变量。

Just to be clear, make_tls_property, which is part of djangotoolbox, makes the TEMPLATE_DIRS setting a per thread variable instead of a global variable so each request response loop gets it's own "version" of the variable.

这篇关于什么/哪里修改django注册使用手机的兄弟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆