1.1.环境搭建 (1)虚拟环境 mkvirtualenv website pip install django==1.11.7 (2)创建项目和app:website和blog (3)设置中文settings.py LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False 运行项目:http://127.0.0.1:8000/ 1.2.模型设计 (1)…
5.1.自定义403,404和500页面 (1)website/urls.py from blog import views as blog_views handler403 = blog_views.permission_denied handler404 = blog_views.page_not_found handler500 = blog_views.page_error (2)views.py def permission_denied(request): ''' return re…
4.1.博客分类 (1)blog_tags.py @register.simple_tag def get_categories(): return Category.objects.all() @register.simple_tag def get_entry_count_of_category(category_name): return Entry.objects.filter(category__name=category_name).count() (2)right_side_bar…
3.1.分页功能 (1)views.py from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger def make_paginator(objects, page, num=3): paginator = Paginator(objects, num) try: object_list = paginator.page(page) except PageNotAnInteger: object_list = p…
2.1.博客首页设计 (1)settings.py MEDIA_ROOT = os.path.join(BASE_DIR,'media').replace("//","/") MEDIA_URL = '/media/' (2)website/urls 添加图片的url from django.conf.urls import url,include from django.contrib import admin from django.conf import se…
6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.contrib.sites', 'django_comments', ] SITE_ID =1 (3)website/url url(r'^comments/', include('django_comments.urls')), (4)修改源码 django_comments/abstracts.py第…
6.1.comments插件 (1)安装 pip install django-contrib-comments (02)settings INSTALLED_APPS = [ 'django.contrib.sites', 'django_comments', ] SITE_ID =1 (3)website/url url(r'^comments/', include('django_comments.urls')), (4)修改源码 django_comments/abstracts.py第…
创建blog的项目结构 关于如何创建一个Django项目,请查看[Python Web开发:使用Django框架创建HolleWorld项目] 创建blog的数据模型 创建一个文章类 所有开发都是数据为基础,首先我们再blog app下的models.py模型中Article,因为是基于Django MVC模式开发,Article类需要继承models.Model类 from django.db import models # Create your models here. class Art…
1.安装python 选择合适python2.7及以上版本安装https://www.python.org/downloads/ 2.建立虚拟环境 这不是必须的,但是建议使用,为每个项目单独引入依赖,避免出现环境问题.对于python3.3以下版本可参考https://virtualenv.pypa.io/en/stable/installation/,python3.3及以上版本参考https://docs.python.org/3/library/venv.html. 3.安装django-…
传送门:https://github.com/1417766861/django-blog(可直接运行,上面有步骤) 效果: 首页: 侧栏: 详情页面: 修改头像,资料,文章发布: 支持添加标签拖拽 粒子背景特效 登陆界面 刚发布的新文章:…