LoginSignup
3
12

More than 5 years have passed since last update.

PythonAnywhereにDjangoアプリをデプロイする

Last updated at Posted at 2019-04-16

環境
OS : macOS Mojave
Anaconda : python3.6.7
Django==2.1.5

準備

Gitのインストール
Githubのアカウント作成
PythonAnywhereのユーザ登録

以下の記事を参考にさせていただきました

GitHubのアカウント登録からリポジトリ操作まで
【Django】PythonAnyWhereにデプロイする

settings.py

末尾に以下の1行を追加

settings.py
ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']

Gitレポジトリの作成

Terminal
$ git init
Initialized empty Git repository in ~/djangogirls/.git/
$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com

.gitignoreの作成

Terminal
touch .gitignore
.gitignore
*.pyc
*~
__pycache__
myvenv
db.sqlite3
/static
.DS_Store

コミット

Terminal
$ git add --all .
$ git commit -m "ooooo, first commit"

Githubのレポジトリ作成とプッシュ

Terminal
$ git remote add origin https://github.com/<your-github-username>/ooooo.git
$ git push -u origin master

PythonAnywhere

bash
$ mkvirtualenv myenv --python=python3.6
$ pip install django
$ pip install (その他必要なパッケージ)

右上、WebタブからAdd a new web app
このときにframework選択画面でDjangoではなく、manual configurationを選択すること(詳しくは参考サイトを)

virtualenvの選択とWSGI Configlation fileの編集をし
コンソールをひらき、以下のコマンドを実行

bash
$ python3 manage.py collectstatic
$ python3 manage.py createsuperuser

staticファイルの場所を選択
WebページトップのReoladを押して更新

アプリページを開いて無事表示されればOK!

追記
PythonAnywhereで

$ python manage.py (コマンド)

とやるとエラーが出たりしたが、本文中にあるようにpython3とうって実行すると上手く実行できた

終わりに

Django Girls Tutorialの手順でやったらうまく行かなかったので、いろいろ調べて一からやってみたらうまくできた。
よろしっかったらご参考までに。

3
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
12