I d like to deliver special versions of my django site for different (mobile-)browser. What are possible solutions to do this?
如何为不同的浏览器使用不同的模版
原标题:
最佳回答
您认为,这确实如此。
def map(request, options=None, longitude=None, latitude = None):
if iPhone in request.META["HTTP_USER_AGENT"]:
user_agent = iPhone
elif MSIE in request.META["HTTP_USER_AGENT"]:
user_agent = MSIE
else: user_agent=
print user_agent
return render_to_response( map/map.html ,
{
user_agent : user_agent
})
页: 1
{% ifnotequal user_agent "iPhone" %}
{% ifequal user_agent "MSIE" %}
{% include map/map_ie.html %}
{% else %}
{% include map/map_default.html %}
{% endifequal %}
{% else %}
{% include map/map_iphone.html %}
{% endifnotequal %}
问题回答
最佳做法:使用 ,在请求中添加额外信息,然后使用在请求中建造的django,将其传送到您的模板中。
from django.shortcuts import render_to_response
from django.template import RequestContext
def my_view_on_mobile_and_desktop(request)
.....
render_to_response( regular_template.html ,
{ my vars to template :vars},
context_instance=RequestContext(request))
之后,在您的模板中,你能够像:
<html>
<head>
{% block head %}
<title>blah</title>
{% if request.mobile %}
<link rel="stylesheet" href="{{ MEDIA_URL }}/styles/base-mobile.css">
{% else %}
<link rel="stylesheet" href="{{ MEDIA_URL }}/styles/base-desktop.css">
{% endif %}
</head>
<body>
<div id="navigation">
{% include "_navigation.html" %}
</div>
{% if not request.mobile %}
<div id="sidebar">
<p> sidebar content not fit for mobile </p>
</div>
{% endif %>
<div id="content">
<article>
{% if not request.mobile %}
<aside>
<p> aside content </p>
</aside>
{% endif %}
<p> article content </p>
</aricle>
</div>
</body>
</html>
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding