创建django项目

  • wsgi -- Web Server Gateway Interface
    •   用来处理client端和server端之间的TCP连接、HTTP原始请求和响应格式

 

  • 创建项目的步骤
    • 安装django:
      •   pip3 install django
    • 创建project:
      •   django-admin startproject mysite
    • 创建app:
      •   python manage.py startapp app01
    • settings配置:
      •   TEMPLATES:
        •   'DIRS': [os.path.join(BASE_DIR, 'templates')]
      •        STATICFILES_DIRS:
        •   STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'statics'), )
        •       STATIC_URL = '/static/'  
      •   INSTALLED_APPS:
        •   加入'app01',然后再同步数据库
    • 生成同步数据库的脚本:
      •   python manage.py makemigrations
    • 同步数据库::
      •   python manage.py migrate
    • 设计代码:urls.py  views.py
    • 返回http响应:
      •   from django.shortcuts import HttpResponse
      •   return HttpResponse()
    • 使用模板:
      •   from django.shortcuts import render
      •   return render(req, "index.html")
    • 启动项目:
      •   python manage.py runserver  127.0.0.1:8090

         

  • STATIC_URL的使用说明
    • STATICFILES_DIRS路径的别名,在html页面中引用js、css时,路径要使用STATIC_URL
    • 例如:<script src="/static/Semantic-UI-CSS-master/semantic.min.js"></script>
posted @ 2018-09-18 14:59  运维00001  阅读(145)  评论(0编辑  收藏  举报