+-
python – 用于移动和桌面的Django WebApp
我用 django制作了网络应用程序,它在桌面浏览器上看起来很漂亮,但在移动浏览器中,有些页面看起来并不完美.
我的模板目录是myproject / template /我想为移动浏览器创建新模板myproject / template_mobile /每当网页通过移动设备访问时,它会重定向到myproject / template_mobile / template,否则它会通过myproject / template /.有没有办法让它形成setting.py或装饰?我不想改变整个视图和旧模板.

提前致谢.

最佳答案
最后我得到了解决方案:
 我使用 django-mobile,根据要求更改settings.py并为此制作了middleware.py.

settings.py:(first follow `django-mobile`)

DESKTOP_TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates'),)
MOBILE_TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates/mobile'),)

然后制作middleware.py

middleware.py
from django.conf import settings

class MobileTemplatesMiddleware(object):
    """Determines which set of templates to use for a mobile site"""

    def process_request(self, request):
        # sets are used here, you can use other logic if you have an older version of Python
        MOBILE_SUBDOMAINS = set(['m', 'mobile'])
        domain = set(request.META.get('HTTP_HOST', '').split('.'))
        if request.flavour=='mobile':
            settings.TEMPLATE_DIRS = settings.MOBILE_TEMPLATE_DIRS
        else:
            settings.TEMPLATE_DIRS = settings.DESKTOP_TEMPLATE_DIRS
点击查看更多相关文章

转载注明原文:python – 用于移动和桌面的Django WebApp - 乐贴网