Run Django on PythonAnywhere

Each version

Create virtualenv for python3

Open terminal.

スクリーンショット 2015-06-28 17.16.36.png

Create a virtualenv on the terminal.

08:20 ~ $ virtualenv --python="python3" env                                                                                          
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in env/bin/python3
Also creating executable in env/bin/python
Installing setuptools, pip, wheel...done.
08:21 ~ $ 

Activate virtualenv.

08:21 ~ $ source env/bin/activate                                                                                                    
(env)08:21 ~ $ 

install django

Install django with pip install django.

(env)08:21 ~ $ pip install django 
Collecting django
Installing collected packages: django
Successfully installed django-1.8.2

Make a project

Create a project with python manage.py startproject PROJECTNAME.

(env)08:27 ~ $ django-admin startproject djexample
(env)08:27 ~ $ 

syncdb

Change to the directory of the created project.

(env)08:34 ~ $ cd djexample/

Syncdb for the time being.

(env)08:35 ~/djexample $ python manage.py syncdb
/home/TakesxiSximada/env/lib/python3.4/site-packages/django/core/management/commands/syncdb.py:24: RemovedInDjango19Warning: The sync
db command will be removed in Django 1.9
  warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: auth, admin, contenttypes, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  No migrations to apply.
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'takesxisximada'): ADMINISTORATOR_NAME
Email address: [email protected]   
Password: 
Password (again): 
Superuser created successfully.
(env)08:35 ~/djexample $ 

Publish to the web

Application settings

Set the domain name. (It cannot be changed if it is a free plan.) スクリーンショット 2015-06-28 17.41.11.png

Select the web framework you want to use. There is Django, but if you select this, it will be Python 2.7 series, Django 1.6 series, so select Manual configuration.

スクリーンショット 2015-06-28 17.41.19.png

Select the Python version. Python 3.4 is an option.

スクリーンショット 2015-06-28 17.41.25.png

I will press Next for the time being. スクリーンショット 2015-06-28 17.41.32.png

At this stage, the new dj example can be managed by Python Anywhere.

virtualenv settings

You can set to use your own virtualenv by pressing ʻEnter path to a virtualenv, if disired`.

スクリーンショット 2015-06-28 17.43.14.png

Like this. スクリーンショット 2015-06-28 17.44.32.png

wsgi file settings

The wsgi file to be read seems to be fixed, so replace the wsgi file under / var / www.

Back up old files for the time being.

(env)08:55 ~/djexample $ cp /var/www/takesxisximada_pythonanywhere_com_wsgi.py /var/www/takesxisximada_pythonanywhere_com_wsgi.py.old 
(env)08:55 ~/djexample $ 

Copy wsgi.py of djexample with the same name as the file originally under / var / www.

(env)08:55 ~/djexample $ cp djexample/wsgi.py /var/www/takesxisximada_pythonanywhere_com_wsgi.py
(env)08:56 ~/djexample $

Then rewrite as follows.

"""
WSGI config for djexample project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
import sys
from django.core.wsgi import get_wsgi_application
path = '/home/TakesxiSximada/djexample'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'djexample.settings'
application = get_wsgi_application()

Actually added the following.

path = '/home/TakesxiSximada/djexample'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'djexample.settings'

WSGI files can also be rewritten from the WEB. スクリーンショット 2015-06-28 18.45.57.png

Add static file settings

Add STATIC_ROOT to settings.py

(env)09:47 ~/djexample $ tail djexample/settings.py 
USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Added static file settings to urls.py

(env)09:48 ~/djexample $ cat djexample/urls.py 
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

collect static

Collect static files with cllect static.

(env)09:50 ~/djexample $ python manage.py collectstatic                                                                                     
You have requested to collect static files at the destination
location as specified in your settings:
    /home/TakesxiSximada/djexample/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
~abridgement~
(env)09:50 ~/djexample $ 

Access the management screen

Restart application

スクリーンショット 2015-06-28 18.51.37.png

Take a look

Go to http://takesxisximada.pythonanywhere.com/admin.

スクリーンショット 2015-06-28 18.52.43.png

Yay.

Recommended Posts

Run Django on PythonAnywhere
[Note] Run Django on Amazon Linux 2
Run django applications on Windows + Apache + mod_wsgi + services.
Run mysqlclient on Lambda
Hello World on Django
Run OpenMVG on Mac
How to run Django on IIS on a Windows server
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
[Django] Notes on using django-debug-toolbar
Run Tensorflow 2.x on Python 3.7
Django environment development on Windows 10
Run Python CGI on CORESERVER
Run unix command on python
Install Django on your Mac
Run IPython Notebook on Docker
Run YOLO v3 on AWS v2
Hello World (beginners) on Django
Run CircuitPython on Seeeduino XIAO
Run Jupyter Notebook on windows
Run FreeBSD on Linux + qemu
Run OpenVino on macOS Catalina
Run YOLO v3 on AWS
Don't lose to Ruby! How to run Python (Django) on Heroku
Run MuJoCo on WSL (2) (also GUI)
Install and run dropbox on Ubuntu 20.04
Preparing to run Flask on EC2
Deploy your Django application on Heroku
Run a Linux server on GCP
Run Python on Schedule on AWS Lambda
Django
Run TensorFlow Docker Image on Python3
python + django + scikit-learn + mecab (1) on heroku
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Implement a Django app on Hy
Run Matplotlib on a Docker container
Try Ajax on the Django page
python + django + scikit-learn + mecab (2) on heroku
Run azure ML on jupyter notebook
Publish DJango page on heroku: Practice
Run python3 Django1.9 with mod_wsgi (deploy)
Run headless-chrome on a Debian-based image
Run XGBoost on Bash on Ubuntu on Windows
Run TensorFlow2 on a VPS server
Run vmware horizon client on Debian
Update applications running on Django 1.7 to Django 1.8
Run PartiQL on Dynamodb via boto3
Run Keras on Google Colaboratory TPU
Run docker-compose on Amazon Linux2 on ARM64
Django blog on heroku: login implementation
Run Yocto on Ubuntu using QEMU.
Run Sesame on Sony's PaSoRi (RCS370)
Periodically run Python on Heroku Scheduler
Run cron on Amazon Linux (set on Linux)
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Django Crispy Tutorial (Environment Building on Mac)
Migrate Django applications running on Python 2.7 to Python 3.5
Run Radeon GPU on Windows on QEMU / KVM
Run servo with Python on ESP32 (Windows)
Use Tabpy with Cloud Run (on GKE)