1

さまざまな (モバイル) ブラウザー用に、django サイトの特別なバージョンを提供したいと考えています。これを行うための可能な解決策は何ですか?

4

2 に答える 2

1

あなたの見解では、このようにsmthgしてください

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
        })

そしてあなたのテンプレートで

{% 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 %}
于 2009-05-29T14:48:50.900 に答える
0

ベスト プラクティス: minidetectorを使用して追加情報をリクエストに追加し、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>
于 2010-11-11T08:01:17.317 に答える