django-localeurlを私のプロジェクトに使用しようとしていますが、ドキュメントに続いてエラーが表示されます。私が欲しいのは、テンプレートで作業このコード作るです:要求がコンテキストにありません
{% load i18n %}
{% load localeurl_tags %}
{% get_available_languages as LANGUAGES %}
{% get_current_language as LANGUAGE_CODE %}
{% for lang in LANGUAGES %}
{% ifequal lang.0 LANGUAGE_CODE %}
<li class="selected">{{ lang.1 }}</li>
{% else %}
<li><a href="{{ request.path|chlocale:lang.0 }}">{{ lang.1 }}</a></li>
{% endifequal %}
{% endfor %}
それからだ:
<li><a href="{{ request.path|chlocale:lang.0 }}">{{ lang.1 }}</a></li>
:私は、問題は、このラインであるこのエラーに
Caught AssertionError while rendering: URL must start with SCRIPT_PREFIX:
を得たhttp://packages.python.org/django-localeurl/usage.html
request.path
は空の文字列です。しかし、なぜ?ブラウザで私は127.0.0.1/hu/
を見ることができるので、もし私が正しいならそれは/hu/
を含むべきです。
私は、単純化のため、仮想環境にdjango 1.3とdjango-localeurl
という新しいプロジェクトを作成しました。 (私が知っているように、重要な部品)
私のsettings.pyは、次のようになります。
LANGUAGES = (
('hu', 'Hungarian'),
('en', 'English'),
('sk', 'Slovakian'),
)
LANGUAGE_CODE = 'hu'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'localeurl.middleware.LocaleURLMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.request",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
)
INSTALLED_APPS = (
'localeurl',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
私は何をしないのですか?
編集1: 私はコンテキストにrequest.path manually
を置くことができます:私が代わりにrequest.path
のテンプレートでrpath
を使用するよりも、
def main(request):
return render_to_response('base.html', {'rpath': request.path})
、しかし、しかし.... request.path
が原因django.core.context_processors.request
の、何かを含める必要がありますTEMPLATE_CONTEXT_PROCESSORS
のURLミドルウェアハックは、私はあなたが探しているものだと思いrequest.path
request.path_infoは良くありません、私が試した、と同じ結果を持っています。 – balazs