diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..39e659cd83a50f47f788a89478b60a1798280396 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/urls.py" @@ -0,0 +1,16 @@ +from django.urls import path, re_path + +from . import views +app_name = 'polls' +urlpatterns = [ + # ex: /polls/ + path('', views.IndexView.as_view(), name='index'), + # ex: /polls/5/ + path('/', views.detail, name='detail'), + # ex: /polls/5/results/ + path('/results/', views.results, name='results'), + # ex: /polls/5/vote/ + path('/vote/', views.vote, name='vote'), + # re_path(r'^(?P\d+)/vote/$', views.vote, name='vote') + path('file/', views.file_test) +] \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/views.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/views.py" new file mode 100644 index 0000000000000000000000000000000000000000..63083566f962e4995cbff13c3cf12a406c605196 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson1/views.py" @@ -0,0 +1,63 @@ +from django.http import HttpResponse, HttpResponseRedirect, Http404, FileResponse +from django.db import transaction +from django.shortcuts import get_object_or_404, render +from django.urls import reverse +from django.views import generic +from .models import Choice, Question +# Create your views here. + +class IndexView(generic.TemplateView): + template_name = "polls/index.html" + + def get_context_data(self, **kwargs): + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = {'latest_question_list': latest_question_list} + return context + +def index(request): + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = {'latest_question_list': latest_question_list} + return render(request, 'polls/index.html', context) + +def detail(request, question_id): + try: + question = Question.objects.get(pk=question_id) + context = { + "question": question + } + except Question.DoesNotExist: + raise Http404("Question does not exist") + return render(request, 'polls/detail.html', context) + +def results(request, question_id): + question = get_object_or_404(Question, pk=question_id) + return render(request, 'polls/results.html', {'question': question}) + + +# @transaction.atomic() +def vote(request, question_id): + question = get_object_or_404(Question, pk=question_id) + try: + selected_choice = question.choice_set.get(pk=request.POST['choice']) + except (KeyError, Choice.DoesNotExist): + # Redisplay the question voting form. + return render(request, 'polls/detail.html', { + 'question': question, + 'error_message': "You didn't select a choice.", + }) + else: + selected_choice.votes += 1 + selected_choice.save() + # Always return an HttpResponseRedirect after successfully dealing + # with POST data. This prevents data from being posted twice if a + # user hits the Back button. + return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) + + +def file_test(request): + filename = "views.py" + with open("polls/views.py", "r", encoding="utf-8") as f: + response = FileResponse(f.read()) + response['content-type'] = "application/octet-stream" + response['content-disposition'] = f"attachment; filename={filename}" + return response \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/15-2-1.png" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/15-2-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..7a985352e8b2943495339078aac3a42dcc85b25e Binary files /dev/null and "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/15-2-1.png" differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/index.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/index.html" new file mode 100644 index 0000000000000000000000000000000000000000..a2efa8bce1d3ca94098a6db992ec1f5ca18c1014 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/index.html" @@ -0,0 +1,456 @@ + + + + + + + + + + + + + + + + Cofess - Web Developer &Designer + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ +
+
+ {% for article in article_list %} + + {% endfor %} +
+
+ + + + + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/models.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..f449c349d39c5d29309d0f03634b554614cb3af7 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/models.py" @@ -0,0 +1,15 @@ +from django.db import models + +# Create your models here. +class Article(models.Model): + title = models.CharField(max_length=200) + text = models.TextField() + url = models.CharField(max_length=200) + update_time = models.DateTimeField(auto_now=True) + create_time = models.DateTimeField(auto_now_add=True) + + class Meta: + db_table = "article" + + def __str__(self): + return f"
" \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..bc623c8e0a894109ca0859b7f4b4c181d64e3e4b --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/settings.py" @@ -0,0 +1,128 @@ +""" +Django settings for myblog project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'tm4)mbtd$bwn!aq-n9&#)m!s5ef#(v06n+q2*%u(mxwe-v4b9b' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'blog.apps.BlogConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'myblog.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, "templates")], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'myblog.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'myblog', + 'USER': 'root', + 'PASSWORD': 'xmt66237029', + 'HOST': '127.0.0.1', + 'PORT': '3306' + }, +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..32d75af35bf36a03fc070e039babfb3686af667d --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson2/urls.py" @@ -0,0 +1,28 @@ +"""myblog URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +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.contrib import admin +from django.urls import path +from django.conf.urls.static import static +from django.conf import settings +from blog.views import IndexView + +urlpatterns = [ + path('admin/', admin.site.urls), + path("", IndexView.as_view()), +] + static(settings.STATIC_URL) + + +print(urlpatterns) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/15-3-1.png" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/15-3-1.png" new file mode 100644 index 0000000000000000000000000000000000000000..0fb41b840257519ed75c238a4d41cf5ea1e44864 Binary files /dev/null and "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/15-3-1.png" differ diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/detail.html" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/detail.html" new file mode 100644 index 0000000000000000000000000000000000000000..c2da63e5913164f104a9661e04c8956b9a749691 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/detail.html" @@ -0,0 +1,1028 @@ + + + + + + + + + + + + + + + + Visual Studio Code个人使用插件整理 | Cofess - Web Developer &Designer + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ + +
+
+
+
+

Visual Studio Code个人使用插件整理

+ +
+
+ {{ article.content|safe }} +
+ +
+
+
+ + +
+ + + + + + + + + + + + + + diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/models.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..c2c8a1d0aef89edcb57740c1e2dbd7da28340f6f --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/models.py" @@ -0,0 +1,39 @@ +from django.db import models +from mdeditor.fields import MDTextField + + +# Create your models here. +class Article(models.Model): + title = models.CharField(max_length=200) + text = MDTextField() + url = models.CharField(max_length=200) + update_time = models.DateTimeField(auto_now=True) + create_time = models.DateTimeField(auto_now_add=True) + + class Meta: + db_table = "article" + + def __str__(self): + return f"
" + + +class Category(models.Model): + article = models.ForeignKey(Article, on_delete=models.CASCADE) + name = models.CharField(max_length=200) + slug = models.CharField(max_length=200) + uri = models.CharField(max_length=200) + + class Meta: + db_table = "category" + + + + +class Tag(models.Model): + article = models.ForeignKey(Article, on_delete=models.CASCADE) + name = models.CharField(max_length=200) + slug = models.CharField(max_length=200) + uri = models.CharField(max_length=200) + + class Meta: + db_table = "tag" \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/settings.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..e2b46210504213cfada17b4782dbf2dc2676eaca --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/settings.py" @@ -0,0 +1,129 @@ +""" +Django settings for myblog project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'tm4)mbtd$bwn!aq-n9&#)m!s5ef#(v06n+q2*%u(mxwe-v4b9b' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'mdeditor', + 'blog.apps.BlogConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'myblog.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, "templates")], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'myblog.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'myblog', + 'USER': 'root', + 'PASSWORD': 'xmt66237029', + 'HOST': '127.0.0.1', + 'PORT': '3306' + }, +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/urls.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..29030947961b8ee6c335a104125d39db83ef9990 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/urls.py" @@ -0,0 +1,29 @@ +"""myblog URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +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.contrib import admin +from django.urls import path +from django.conf.urls.static import static +from django.conf import settings +from blog.views import IndexView, DetailView + +urlpatterns = [ + path('admin/', admin.site.urls), + path("", IndexView.as_view()), + path("///", DetailView.as_view()), +] + static(settings.STATIC_URL) + + +print(urlpatterns) \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/views.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/views.py" new file mode 100644 index 0000000000000000000000000000000000000000..6980fd1c69edaada4f4cdd35a3ce950b372b95d1 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\350\214\227\350\214\227\346\230\257\345\217\252\345\201\207\351\270\275\345\255\220/week15/lesson3/views.py" @@ -0,0 +1,44 @@ +from django.shortcuts import render +from django.views.generic import TemplateView +from .models import Article +# Create your views here. +import math +import markdown + + +class IndexView(TemplateView): + template_name = "index.html" + + def get(self, request, *args, **kwargs): + article_list = Article.objects.order_by("-create_time") + for article in article_list: + article.pub_date = article.create_time.strftime("%m-%d").replace("-", "月") + article.length = len(article.text) + article.read_time = math.ceil(len(article.text)/180) if article.text else 0 + # 外键可以通过以下方式获取到集合 + article.categories = article.category_set.values() + article.tags = article.tag_set.values() + # cate_list = Category.objects.filter(article_id=article.id) + context = { + "article_list": article_list, + } + return self.render_to_response(context) + +class DetailView(TemplateView): + template_name = "detail.html" + + def get(self, request, *args, **kwargs): + article = Article.objects.get(url=request.path) + content = "" + for line in article.text.split("\n"): + content += line.strip(" ") if "```" in line else line + content += "\n" + article.content = markdown.markdown(content, extensions=[ + 'markdown.extensions.extra', # 转换标题, 字体等 + 'markdown.extensions.codehilite', # 添加高亮功能 + 'markdown.extensions.toc', # 将表单渲染为html document类型 + ]) + context = { + "article": article, + } + return self.render_to_response(context) \ No newline at end of file