• django


    安装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同级
     
     
    mysql
    DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME':'saku',
    'USER':'root',
    'PASSWORD':'root',
    'HOST':'localhost',
    'PORT':'3306',
    }
    }
  • 相关阅读:
    AFNetworking 3.0迁移指南
    富文本常用封装(NSAttributedString浅析)
    如何在 Objective-C 的环境下实现 defer
    iOS之深入了解控制器View的加载
    10+年程序员总结的20+条经验教训
    Foundation: NSNotificationCenter
    做一款仿映客的直播App?看我就够了
    AFNetworking源码分析
    WWDC2016 Session笔记 – Xcode 8 Auto Layout新特性
    iOS页面间传值的一些方式总结
  • 原文地址:https://www.cnblogs.com/Maskisland/p/8452815.html
Copyright © 2020-2023  润新知