Open terminal.
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 with pip install django
.
(env)08:21 ~ $ pip install django
Collecting django
Installing collected packages: django
Successfully installed django-1.8.2
Create a project with python manage.py startproject PROJECTNAME
.
(env)08:27 ~ $ django-admin startproject djexample
(env)08:27 ~ $
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 $
Set the domain name. (It cannot be changed if it is a free plan.)
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
.
Select the Python version. Python 3.4 is an option.
I will press Next for the time being.
At this stage, the new dj example can be managed by Python Anywhere.
You can set to use your own virtualenv by pressing ʻEnter path to a virtualenv, if disired`.
Like this.
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.
(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')
(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 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 $
Go to http://takesxisximada.pythonanywhere.com/admin.
Yay.
Recommended Posts