diff --git a/no_ipv4_here/templates/no_ipv4_here/index.html b/no_ipv4_here/templates/no_ipv4_here/index.html new file mode 100644 index 0000000..4b97637 --- /dev/null +++ b/no_ipv4_here/templates/no_ipv4_here/index.html @@ -0,0 +1,37 @@ +{% load static from staticfiles %} + + + + + + + + +
+

+ Sorry, this part of {{ domain }} is not reachable by IPv4. Please + upgrade to IPv6 and try to reach {{ domain }} again.

+
+ipv6onlyhosting-ungleich-deadend + + + \ No newline at end of file diff --git a/no_ipv4_here/views.py b/no_ipv4_here/views.py index 350b858..5059129 100644 --- a/no_ipv4_here/views.py +++ b/no_ipv4_here/views.py @@ -1,23 +1,23 @@ -from django.http import HttpResponse +from urllib.parse import urlsplit + +from django.views.generic import TemplateView # Create your views here. -def index(request): - back_to_url = "" - if "back_to" in request.GET: - back_to_url = request.GET["back_to"] - elif 'HTTP_HOST' in request.META: - back_to_url = request.META['HTTP_HOST'] - if back_to_url != "": - return HttpResponse( - """Sorry, this part of domain is not reachable by IPv4. - Please upgrade to IPv6 and try to reach {domain} again.""".format( - domain=back_to_url - ) - ) - else: - return HttpResponse( - """Sorry, this part of domain is not reachable by IPv4. - Please upgrade to IPv6 and try to reach the domain again.""" - ) +class IndexView(TemplateView): + template_name = 'no_ipv4_here/index.html' + + def get_context_data(self, **kwargs): + context = super(IndexView, self).get_context_data(**kwargs) + back_to_url = "" + if "back_to" in self.request.GET: + back_to_url = self.request.GET["back_to"] + elif 'HTTP_HOST' in self.request.META: + back_to_url = self.request.META['HTTP_HOST'] + context['back_to_url'] = back_to_url + if back_to_url != "": + context['domain'] = (urlsplit(back_to_url)).netloc + else: + context['domain'] = "the domain" + return context diff --git a/static/img/ipv6onlyhosting-ungleich-deadend.jpg b/static/img/ipv6onlyhosting-ungleich-deadend.jpg new file mode 100644 index 0000000..2e1bdce Binary files /dev/null and b/static/img/ipv6onlyhosting-ungleich-deadend.jpg differ diff --git a/ungleich_no_ipv4_here/settings.py b/ungleich_no_ipv4_here/settings.py index f1eef55..c72263a 100644 --- a/ungleich_no_ipv4_here/settings.py +++ b/ungleich_no_ipv4_here/settings.py @@ -62,8 +62,8 @@ ROOT_URLCONF = 'ungleich_no_ipv4_here.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates')] - , + 'DIRS': [os.path.join(BASE_DIR, + 'no_ipv4_here/templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -123,3 +123,7 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'static'), +) diff --git a/ungleich_no_ipv4_here/urls.py b/ungleich_no_ipv4_here/urls.py index 4861c37..ee511ed 100644 --- a/ungleich_no_ipv4_here/urls.py +++ b/ungleich_no_ipv4_here/urls.py @@ -13,12 +13,16 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf.urls import url from django.contrib import admin +from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import path -from no_ipv4_here import views +from no_ipv4_here.views import IndexView urlpatterns = [ - path('', views.index, name='index'), + url(r'^$', IndexView.as_view(), name='index'), path('admin/', admin.site.urls), ] + +urlpatterns += staticfiles_urlpatterns()