Oz Tiram 1 жил өмнө
parent
commit
b46a8e0d2e
4 өөрчлөгдсөн 21 нэмэгдсэн , 10 устгасан
  1. 1 1
      Pipfile
  2. 3 2
      catster/settings.py
  3. 5 0
      catster/urls.py
  4. 12 7
      catster/views.py

+ 1 - 1
Pipfile

@@ -8,7 +8,7 @@ name = "pypi"
 [packages]
 
 uwsgi = "*"
-django = "==2.1.7"
+django = ">=2.1.7"
 
 
 [dev-packages]

+ 3 - 2
catster/settings.py

@@ -37,6 +37,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'catster'
 ]
 
 MIDDLEWARE = [
@@ -54,7 +55,7 @@ ROOT_URLCONF = 'catster.urls'
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [],
+        'DIRS': ['templates'],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
@@ -116,5 +117,5 @@ USE_TZ = True
 
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/2.1/howto/static-files/
-
+STATIC_ROOT = 'static'
 STATIC_URL = '/static/'

+ 5 - 0
catster/urls.py

@@ -22,3 +22,8 @@ urlpatterns = [
     path('admin/', admin.site.urls),
     re_path(r'^$', catster.views.index),
 ]
+
+from django.conf import settings
+from django.conf.urls.static import static 
+if settings.DEBUG:
+    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

+ 12 - 7
catster/views.py

@@ -2,6 +2,7 @@ from ipaddress import ip_address
 
 
 from django.http import HttpResponse
+from django.template import loader
 
 
 def get_client_ip(request):
@@ -13,17 +14,21 @@ def get_client_ip(request):
     return ip
 
 
-def no_cats_here():
-    return HttpResponse("no cats purring here, only via ipv6")
+#def no_cats_here():
+#    return HttpResponse("no cats purring here, only via ipv6")
 
 
-def cute_cat():
-    return HttpResponse("purrr ...")
+def cute_cat(request):
+    template = loader.get_template("catster/index.html")
+    context = {}
+    return HttpResponse(
+            template.render(context, request)
+            )
 
 
 def index(request):
     ip = get_client_ip(request)
-    if ip_address(ip).version == 4:
-        return no_cats_here()
+    #if ip_address(ip).version == 4:
+    #    return no_cats_here()
 
-    return cute_cat()
+    return cute_cat(request)