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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/re_test.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/re_test.py" new file mode 100644 index 0000000000000000000000000000000000000000..571b1e4752933dee77e8e9022b5157a53ea0acb4 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/re_test.py" @@ -0,0 +1,8 @@ +import re + +# 变量匹配: +# path('/vote/', views.vote, name='vote'), +#正则匹配 +path = "5/vote/" +m = re.match(r'^(?P\d+)/vote/$', path) +print(m.group("question_id")) \ 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..271025fb01428ce0ca972586d09f60d649f807fd --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/urls.py" @@ -0,0 +1,19 @@ +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') +] + + + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/\345\215\201\344\272\224\345\221\250\347\273\203\344\271\240.md" "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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/\345\215\201\344\272\224\345\221\250\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..4f133a800903e45e73ec95f21a0336586078702a --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\200\350\212\202/\345\215\201\344\272\224\345\221\250\347\273\203\344\271\240.md" @@ -0,0 +1,71 @@ +HttpResponse类型 + +模板 + +``` +return render(request, 'polls/requests.html',{'question':question}) +``` + +返回字符串 + +``` +return HttpResponse('test') +``` + +返回 JSON格式字符串 + +``` +return JsonResponse({'choice':2}, safe=False) +``` + +返回文件 + +``` +from django.http import FileResponse + +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 +``` + +返回异常 + + + +基于函数的视图 + +``` +def index(request): + """ + request 就是作为参数传递进来的请求对象 + :param request: + :return: HttpResponse 处理完请求的返回对象 + """ + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = { + 'latest_question_list': latest_question_list, + } + return render(request, 'polls/index.html', context) +``` + +用函数实现`restful api` + +``` +class IndexView(generic.View): + def get(self, *args, **kwargs): + pass + + def post(self, *args, **kwargs): + pass + + def put(self, *args, **kwargs): + pass + + def delete(self, *args, **kwargs): + pass +``` + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/admin.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/admin.py" new file mode 100644 index 0000000000000000000000000000000000000000..a38753275e667ca9a2bd574fd9f899f3f4c25400 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/admin.py" @@ -0,0 +1,22 @@ +from django.contrib import admin +from .models import Article, Category, Tag +# Register your models here. + + +class CategoryInline(admin.TabularInline): + model = Category + + +class TagInline(admin.TabularInline): + model = Tag + + +class ArticleAdmin(admin.ModelAdmin): + inlines = [CategoryInline, TagInline] + + list_display = ['title', 'create_time'] + + +admin.site.register(Article, ArticleAdmin) + + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/detail.html" new file mode 100644 index 0000000000000000000000000000000000000000..77a9eb89c727baebb64e361958ea3cba1183c9d6 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/detail.html" @@ -0,0 +1,1029 @@ + + + + + + + + + + + + + + + + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/index.html" new file mode 100644 index 0000000000000000000000000000000000000000..aeacbfe48042b880bf4dbd7eebb40cea0e1a027d --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/index.html" @@ -0,0 +1,461 @@ + + + + + + + + + + + + + + + + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..a2feb81c00aef3d9c90519ddeaf9e4647fcffb4b --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/models.py" @@ -0,0 +1,41 @@ +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" + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/views.py" new file mode 100644 index 0000000000000000000000000000000000000000..d40d537a688f7b9898b7d2f1dcdc50272eb2cfe5 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\270\211\350\212\202/views.py" @@ -0,0 +1,46 @@ +from django.shortcuts import render +from django.views.generic import TemplateView +from .models import Article, Category +# 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) + 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/manage.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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/manage.py" new file mode 100644 index 0000000000000000000000000000000000000000..b2d940d51c94034217efc78330d1eecd195e06b0 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/manage.py" @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/models.py" new file mode 100644 index 0000000000000000000000000000000000000000..7c8feff221c7c0af69d4335c745d0d3a86534d9c --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/models.py" @@ -0,0 +1,16 @@ +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"
" 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/settings.py" new file mode 100644 index 0000000000000000000000000000000000000000..e2662964fe5e27e241003ccc99640aa715a3c289 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/settings.py" @@ -0,0 +1,130 @@ +""" +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 = '$q4%gy_35s!nyw5uiz!_0ic%-q9s*+#ytp1*iue_u&@yv_jr_a' + +# 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': 'lmc.123', + '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/ + +# http://127.0.0.1:8000/static/xxx.js + +STATIC_URL = '/static/' +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] \ 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/urls.py" new file mode 100644 index 0000000000000000000000000000000000000000..6d0b3c4dbd9408b416f649e10a0b5ad707b0acd0 --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/urls.py" @@ -0,0 +1,26 @@ +"""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) \ 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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/views.py" new file mode 100644 index 0000000000000000000000000000000000000000..64be1f042159a8acecb8ad9db3c98bbfca1c495f --- /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_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250 /3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\272\224\345\221\250_\347\254\254\344\272\214\350\212\202/views.py" @@ -0,0 +1,23 @@ +from django.shortcuts import render + +# Create your views here. +from django.views.generic import TemplateView +from .models import Article +import math + +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 + + + context = { + "article_list": article_list + + } + return self.render_to_response(context) \ No newline at end of file