91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》
  • 首頁 > 
  • 教程 > 
  • 開發技術 > 
  • DJango-如何快速準備Python虛擬開發環境并快速定制一個項目

DJango-如何快速準備Python虛擬開發環境并快速定制一個項目

發布時間:2020-06-23 22:31:42 來源:網絡 閱讀:1369 作者:scobe 欄目:開發技術

Django是1.11,Python3.6,Mac OS

中英文混雜,主要為為自己記錄用,時間有限,見諒。


  • Create Dev Directory for general project storage

    • $cd ~/projects

    • $mkdir Dev && cd Dev

  • Create Virtual Environment

    • $mkdir project_name && cd project_name

    • $pip install virtualenv virtualenvwrapper

    • $mkdir ~/.venvs

    • $export WORKON_HOME=~/.venvs

    • $export PATH=/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH

    • $source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh

    • $mkvirtualenv —python=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 project_name

    • To activate project_name virtual env:

    • $workon project_name

    • To deactivate project_name, just 

    • $deactivate



  • Install Django & Start Project

    • $pip install django==1.11.4

    • $mkdir src && cd src

    • $django-admin startproject project_name . 

    • (Don’t forget the “.” )

  • Create New Settings Module

    • Currently working in ./src

    • $cd project_name

    • $mkdir settings && cd settings

    • Change BASE_DIR in settings.py:

    • BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    • To

    • BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

    • Move default settings.py into new settings module and rename settings.py to base.py

    • $mv settings.py ./settings/base.py

    • $cd settings/

    • Copy base.py to make new (local.py, dev.py & pro.py) files:

    • $cp base.py local.py 

    • $cp base.py dev.py

    • $cp base.py pro.py

    • To use local.py as our starting point since we use sqlite3 database. We will move to dev.py with development is going forward and finally pro.py when we decide to release our product.

    • In local.py use the following settings. 


    • from .base import *
      
      DEBUG = True
      
      ALLOWED_HOSTS = []
      
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.sqlite3',
              'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
          }
      }
    • Remove the related contents from base.py accordingly.

    • Edit manage.py and replace os.environ.setdefault("DJANGO_SETTINGS_MODULE", “project_name.settings") with os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings.local")



    • Or you can set env variable:

    • $export DJANGO_SETTINGS_MODULE = project_name.settings.local

    • Or you can directly run manage.py with settings options.e.g:

    • $python manage.py runserver —settings=project_name.settings.local

    • $python manager.py createsuperuser (to create a super user account)

    • Openhttp://127.0.0.1:8000/, you should see the successful message.

    • You also can loginhttp://127.0.0.1:8000/admin using the super user. There you can create and update groups and users. 

    • You can use pip freeze to save a list for installed packages.

    • $pip freeze > requirements.txt

    • (You can use $pip install-r requirements.txt to install all the packages for dependency)



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

仙桃市| 蒙自县| 东台市| 长泰县| 井研县| 阳春市| 乐安县| 林西县| 景泰县| 托里县| 佛冈县| 宁南县| 昭苏县| 洛川县| 襄汾县| 婺源县| 新津县| 淳化县| 涿鹿县| 九台市| 西昌市| 色达县| 富顺县| 自治县| 易门县| 惠东县| 安义县| 缙云县| 新竹县| 昌都县| 比如县| 枝江市| 抚顺县| 玉龙| 江西省| 泾源县| 蒲城县| 利川市| 车险| 随州市| 文化|