码迷,mamicode.com
首页 > 其他好文 > 详细

django

时间:2018-02-18 15:59:00      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:container   conf   name   实用   site   博客   lan   install   标签   

安装django

sudo pip install django==1.8.3

实用虚拟环境

source venv/bin/activate

deactivate

创建django 项目

django-admin startproject tutorial

cd tutorial
python manage.py startapp blog
 
python manage.py migrate
python manage.py runserver
 
配置models
class Article(models.Model):
    title = models.CharField(u"博客标题",max_length = 100)        #博客标题
    category = models.CharField(u"博客标签",max_length = 50,blank = True)       #博客标签
    pub_date = models.DateTimeField(u"发布日期",auto_now_add = True,editable=True)       #博客发布日期
    update_time = models.DateTimeField(u‘更新时间‘,auto_now=True,null=True)
    content = models.TextField(blank=True, null=True# 博客文章正文
 
    def __unicode__(self):
        return self.title
 
    class Meta:     #按时间下降排序
        ordering = [‘-pub_date‘]
        verbose_name = "文章"
        verbose_name_plural = "文章"
 
同步数据库
python manage.py makemigrations
 
创建超级用户
python manage.py createsuperuser
 
配置urls
新建blog.urls
tutorial.urls
import blog.urls as blog_url
urlpatterns = [
    url(r‘^admin/‘, include(admin.site.urls)),
    url(r‘^ueditor/‘,include(djud_urls)),
]
 
 
blog.urls
from django.conf.urls import url
from . import views

urlpatterns = [
    url(r‘^test/‘, views.Test, name="blog_test"),
    url(r‘^post/(?P<id>\d+)/$‘,views.Detail,name="blog_detail"),
    url(r‘^home/‘,views.home,name="blog_home"),
]
 
 
setting配置,配置HTML文件
‘DIRS‘: [os.path.join(BASE_DIR,"templates")],templates文件和managy.py同级

django

标签:container   conf   name   实用   site   博客   lan   install   标签   

原文地址:https://www.cnblogs.com/Maskisland/p/8452815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!