Tip:
Highlight text to annotate it
X
Hello, my name is Daniel and I'll be walking you through how to setup a Django application with WebFaction.
If you're new to WebFaction, you should know that we make it quick and easy to setup a brand new Django installation.
If you haven't yet created an account with WebFaction, please check out WebFaction.com.
Django is a Python language web framework which allows you to create applications with a minimum of time, effort, and code.
You can learn more about Django at djangoproject.com.
We'll also have links to additional Django and Python resources at the end of this screencast.
To follow along with this tutorial you will need a WebFaction account and some basic shell and Python experience.
I'm going to assume you know how to *** your account, 'cd' and 'ls' your way around, and work the editor of your choice.
Please stop and review the man pages if I use a command you're unfamiliar with.
Likewise, I'm going to assume you know a little about Python, its syntax, and how to enter new statements.
Here's a quick overview of what we'll be accomplishing.
We're going to be creating a pastebin website where you can copy and paste arbitrary snippets of text to the web.
For an example, check out pastebin.com.
Let's start by logging into the WebFaction control panel.
Once you're logged in click 'Domains / Websites' then 'Applications'.
When the application list loads, scroll to the bottom and click the 'new' button.
Now let's create a new Django application.
First, give your app a name. I'll call mine 'django_paste'.
Now, select 'Django (1.1)/mod_wsgi'.
Now click 'Create' and wait for the installer to finish.
Let's see what the installer did.
Open a terminal session and log in to your SSH account.
Now, 'cd' into your 'webapps' directory and take a look at the directory listing.
You'll find a new directory there named after your Django installation.
Take a look at its contents.
There you'll find directories containing Apache, Python, and a Django project,
as well as a WSGI configuration file.
Now let's create two applications to serve static media.
This will conserve memory and speed up page loads.
First, let's create an app to serve the admin site media.
Click the 'Add new' button.
Now, give your app a name. I'll call mine 'admin_media'.
Next, select 'Symbolic link to static-only'.
Now, enter the path to the admin media in the 'extra_info' field.
Now, click 'Create'.
Now we can create a static media application for our own static media.
Now let's create a database to store our data.
First, click 'Databases' then 'Create new database'.
Now, select 'PostgreSQL' from the type menu.
Next, enter a database name. I'll call mine 'demo_paste'.
Now, click 'Create'.
Take a note of the password. We'll be entering that in a configuration file later on.
Now we're set to create a website entry to proxy requests to our three new apps.
Click 'Domains / Websites' then 'Websites'.
Now, click the 'New' button.
Next, enter a name for this entry. I'll call mine 'paste'.
Now, select a domain for this site.
Let's add our apps to this entry.
Start by clicking the 'New' button.
Now, select your Django application from the 'App' menu.
Then, enter a slash to denote the root path.
Click the 'Add new' button again.
Now select the static media app from the 'App' menu.
Then enter '/media' in the 'URL path' field.
Click the 'Add new' button one last time.
Now enter '/meda/admin' in the 'URL path' field.
Then click 'Create'.
Let's return to our SSH session and configure some Django settings.
If you haven't done so already, navigate to your Django application directory.
Then change to your 'myproject' directory.
Open 'settings.py' with a text editor.
Enter your name and email address to receive administrative emails.
Now complete the database engine setting for PostgreSQL.
Now fill in the database name and database user settings.
On WebFaction these values are the same.
Enter the database password provided by the control panel.
Now fill in the media root field.
This will be the path to the static media application.
Also complete the media URL field.
This will include the domain name you selected on the control panel and the word 'media'.
Fill in the admin media prefix.
This will look much like the media URL but with 'admin' appended.
Insert the template directory.
Lastly, add 'django.contrib.admin' to the installed apps.
Now, save and close the settings file.
Next, open 'urls.py' for editing.
Uncomment these lines to enable the admin site.
Now save and close the file.
We can now synchronize the database.
Run 'manage.py' with the 'syncdb' command.
You'll be prompted to create a superuser. Do so now.
Now we can restart the server to see if everything's working.
Return to the parent directory, then 'cd' into the 'apache2' directory.
Here you'll find a directory called 'bin'. Switch to that directory now.
Now execute 'restart' to restart the Apache server.
Let's check our handiwork by logging into the admin site.
In your web browser, open the admin site URL.
Now log in with the username and password you created previously.
Now we have verified that the admin site is working properly.
Now open the root URL for the Django site.
As you can see, this site doesn't do anything yet.
Let's download and install a Django application to fix the situation.
Now return to the SSH session in the 'myproject' directory.
Now use 'wget' to download the demonstration archive.
Then 'unzip' the archive.
Two directories have been created: one for the application and one for templates.
Open 'settings.py' with your editor.
Now add 'myproject.paste' to your installed apps.
Then save and close the file.
Now open 'urls.py'.
Now add a url pattern to include the paste app's urls.
Then save and close the file.
Now, resynchronize the database.
Finally, restart Apache.
Let's test the results in the web browser.
Open the site at the root URL.
Now try creating a paste.
And it works!
This concludes the screencast.
To learn more about Python, check out Dive Into Python by Mark Pilgrim.
It's available at diveintopython.org.
To learn more about Django, check out the Django documentation at docs.djangoproject.com.
Finally, if you have any questions, check out the WebFaction forum at forum.webfaction.com.
Thanks for watching.