+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED
I failed at creating my first app. Being a raw noob, I gathered all the tutorials and forum posts I found and very carefully wrote down every step I followed as if doing ort of a tutorial for myself, since I plan on host with PythonAnywhere soon.
Nevertheless, I failed again. I am getting an Unhandled Exception and I cannot understand the error log:
I'd really appreciate help in trying to identify what is it that I'm doing wrong. These are my notes, 99% of it is copied from tutorials and other posts, which I though would be helpful to have in a single location:
1 Setup my environment and virtual environment
1.1 Log in to PythonAnywhere, and create a new Web app:
1.2 Go to the "Web" tab.
1.3 Select the "Add a new web app" option on the left-hand side.
1.4 If you have a Web Developer account, specify the domain you want your web app to appear on, then click "Next"
1.5 Select the "Manual configuration" option from the list.
1.6 Click "Next", and wait for the system to tell you that the web app has been created.
1.7 Check I have a web app -- go to nimbiotics.pythonanywhere.com to see the simple site that was generated.
1.8 Edit .bashrc to contain the following line:
source virtualenvwrapper.sh
1.9 Open a bash console. If you already have a bash console running, you have to source your bash by typing:
16:37 ~ $ source ~/.bashrc
1.10 Create the virtualenv:
18:23 ~/projects $ mkvirtualenv nrpccms
New python executable in nrpccms/bin/python2.7
Also creating executable in nrpccms/bin/python
Installing setuptools............done.
Installing pip...............done.
1.11 You can check it works -- the prompt should show the (nrpccms) prefix, and you can check which pip returns the virtualenv pip:
(nrpccms)20:01 ~ $ which pip
/home/nimbiotics/.virtualenvs/nrpccms/bin/pip
2 Fork project from git repository
2.1 Create Projects' folder:
(nrpccms)20:10 ~ $ cd
(nrpccms)20:10 ~ $ mkdir projects
(nrpccms)20:11 ~ $ cd projects
2.2 Fork project from git repository:
(nrpccms)20:11 ~/projects $ git clone https://github.com/nimbiotics/nrpccms
Cloning into 'nrpccms'...
remote: Counting objects: 339, done.
remote: Compressing objects: 100% (242/242), done.
remote: Total 339 (delta 80), reused 339 (delta 80)
Receiving objects: 100% (339/339), 5.64 MiB | 1.60 MiB/s, done.
Resolving deltas: 100% (80/80), done.
Checking out files: 100% (95/95), done.
3 Finish setting up your virtualenv:
(nrpccms)20:15 ~/projects/nrpccms (master)$ cd
(nrpccms)20:15 ~ $ cdproject
(nrpccms)20:15 ~/projects/nrpccms (master)$
3.1 Check your virtualenv's project folder is working :
(nrpccms)20:15 ~/projects/nrpccms (master)$ cd
(nrpccms)20:15 ~ $ cdproject
3.2 Install your project's requirements:
(nrpccms)20:15 ~/projects/nrpccms (master)$ pip install -r requirements/requirements.txt
4 Static files
Because we had to use manual web app creation to use this virtualenv (instead of PythonAnywhere's built-in Django web app quick-start option, which you'll remember uses an older version of Django), one thing is missing: Configuration for static file mappings.
4.1 To fix this, go to the "Web" tab, select your domain at the left if it's not already selected, then in the "Static files" table:
4.2 Click on the "Enter URL" and enter /static/admin/, then hit return.
4.3 Click on the "Enter path" on the same line, and enter /home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/site-packages/django/contrib/admin/static/admin
4.4 Click on the "Enter URL" and enter /static/, then hit return.
4.5 Click on the "Enter path" on the same line, and enter /home/nimbiotics/.projects/nrpccms/static/
4.6 Edit urls.py. Uncomment the admin lines if you need to, but most importantly use staticfiles_urlpatterns to serve static pages. Your urls.py should read something like this:
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
# Admin interface
# ---------------
urlpatterns = patterns('',
# [EG] url(r'^<my project name>/', include('<my project name>.foo.urls')),
url(r'^admin/', include(admin.site.urls)),
)
# HOMEPAGE FOR A BLOG-ONLY SITE
# -----------------------------
# My case!
url("^$", "mezzanine.blog.views.blog_post_list", name="home"),
# MEZZANINE'S URLS
# ----------------
("^", include("mezzanine.urls")),
# Error pages
# -----------
handler404 = "mezzanine.core.views.page_not_found"
handler500 = "mezzanine.core.views.server_error"
# This is needed to serve static files like images and css
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
5 WSGI
5.1 From PythonAnywhere->Dahsboard->Web, click on the link that contains your wsgi configuration; the link right next to “It is configured via a WSGI file stored at:” and edit it to look like below. The most important thing to remembert here is that path has to point to nrpccms's parent directory
import os
import sys
path = '/home/nimbiotics/projects'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'nrpccms.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
6 The database
Because of the way PythonAnywhere serves its files; a MySQL database will get served faster than a sqlite3 database, so here we go.
6.1 Create db nrpccms in “PythonAnywhere->Dashboard->Databases”
6.2 Edit your settings.py so DATABASES contains your db credentials:
# ...
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "nimbiotics$nrpccms",
"USER": "nimbiotics",
"PASSWORD": "***MYSQL_PASSWORD***",
"HOST": "mysql.server",
"PORT": "",
}
}
# ...
6.3 Create your database in the console:
(nrpccms)18:55 ~/projects/nrpccms (master)$ ./manage.py createdb