だから、私は Django に非常に慣れていませんが、(https://docs.djangoproject.com/en/1.4/intro/tutorial01/) のチュートリアルを数回完了しており、かなりよく理解できていると感じています。 .
私が取り組みたい次の項目は、ミドルウェアの作成、インストール、構成です (より具体的には、ローカル ホストがサイトにアクセスしたときに正常にプルアップし、ローカル ホスト以外の誰かがそれをプルアップするようにしようとしています) google.com またはその他のランダムなサイトに転送されます。) 私は主に、上司の要求に応じてビルドの経験を積むためにこれを行っているので、どんな助けも大歓迎です! :)
次のサイトを読みましたが、URL リダイレクトを機能させるにはどうすればよいかわかりません。
$https://docs.djangoproject.com/en/dev/topics/http/middleware/?from=olddocs
$https://docs.djangoproject.com/en/dev/ref/middleware/
$http://djangosnippets.org/snippets/510/
上記のサイト (www.djangosnippets.org) からピックアップしたコード
import re
from django.http import HttpResponsePermanentRedirect
from django.conf import settings
class UrlRedirectMiddleware:
"""
This middleware lets you match a specific url and redirect the request to a
new url.
You keep a tuple of url regex pattern/url redirect tuples on your site
settings, example:
URL_REDIRECTS = (
(r'www\.example\.com/hello/$', 'http://hello.example.com/'),
(r'www\.example2\.com/$', 'http://www.example.com/example2/'),
)
"""
def process_request(self, request):
host = request.META['HTTP_HOST'] + request.META['PATH_INFO']
for url_pattern, redirect_url in settings.URL_REDIRECTS:
regex = re.compile(url_pattern)
if regex.match(host):
return HttpResponsePermanentRedirect(redirect_url)