在pythonanywhere.com免費網站建立虛擬機環境以及django網站
阿新 • • 發佈:2018-07-31
ima dir 靜態 cfile use imp bubuko 1.8 java
註冊,添加App,選擇python3.5,然後打開控制臺
- 搭建python3.5虛擬環境
python --version
virtualenv -p /usr/bin/python3.5 VENV
source VENV/bin/activate
- 安裝django
pip install "django<1.9"
- 創建網站
django-admin startproject mvote
cd mvote
python manage.py startapp mysite
- 可以通過網站的file,進行上傳template,static file等文件
- 修改setting.py文件
- INSTALLEN_APP加入mysite
- ALLOWED_HOSTS = [‘*‘]
LANGUAGE_CODE = ‘zh-CN‘ TIME_ZONE = ‘Asia/Beijing‘ USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = ‘/static/‘ STATICFILES_DIRS = [ os.path.join(BASE_DIR,‘static‘), ] STATIC_ROOT = "/home/guguobao/mvote/staticfiles/"
點擊它,修改以下內容,去此之外,還要修改mvote/wsgi.py為同樣的內容
# +++++++++++ DJANGO +++++++++++ # To use your own django app use code like this: import os import sys # ## assuming your django settings file is at ‘/home/guguobao/mysite/mysite/settings.py‘ ## and your manage.py is is at ‘/home/guguobao/mysite/manage.py‘ path = ‘/home/guguobao/mvote‘ if path not in sys.path: sys.path.append(path) os.environ[‘DJANGO_SETTINGS_MODULE‘] = ‘mvote.settings‘ # then: from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
- 修改網頁的靜態URL
在pythonanywhere.com免費網站建立虛擬機環境以及django網站