You are not logged in.
This is post is to help newbies who are moving their existing Django app from Windows to WebFaction - it basically goes over the stumbling blocks I encountered in this process:
1. INSTALL DJANGO
In case you didn't ask for Django to be installed as an app, do it now:
a. In the Webfaction control panel, go "Websites/domains" and select "Application"
b. Click the little icon to add an application, and select Django - use the name "django" to following along...
c. go "Websites/domains" and select "websites". Assign your application to your domain.
2. UPLOAD YOUR EXISTING PROJECT
Now use an FTP (or SFTP) client to view the files on your account. User/pass are either the same as control panel, or set up in control panel.
You should see a "webapps" directory which contains a "django" directory, which contains "apache2" and "myproject". "myproject" is the name of sample django project created by WebFaction's tool. To use your own project name, do the following:
a. Copy your projects files under the "django" directory, so that this directory now contains three directories: "apache", "myproject" and "my_existing_project" (for example).
b. To tell apache to serve your application, edit the file /apache2/conf/httpd.conf and change the following line:
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
to
SetEnv DJANGO_SETTINGS_MODULE my_existing_project.settings
3. SERVE STATIC CONTENT
If you're serving static content (images) and you used the Django built-in view to serve them (i.e. a line like this in urls.py:
(r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'c:/djangocode/myproject/main/images/'}),
you'll want to change this now.
a. In control panel go "websites/applications" | "applications"
b. create a new application of type "Static/CGI/PHP". The name is the directory of the content, eg. "images" or "media"
c. edit your httpd.conf file again and add the following lines at the end. This tells apache not to use Django to serve your files:
<Location "/images">
SetHandler None
</Location>
(where "/images" is the directory name of your static content - change as appropriate)
d. In your Django code, get rid of the URL config line mentioned above. Your files will be served by Apache without Django being involved. Leaving this line in gives a cryptic "proxy error, access denied" in WebFaction.
d. select "websites/applications" | "websites"
and add your new application to your existing website, along with the directory "/images" (for example)
4. DATABASE
You need to create your database in control panel by selecting "databases" | "add" and then modify your settings.py file to match the new database settings (type, user, pass). I only tried with MySQL and it all just worked. After changing settings.py you need to do a syncdb:
Now use an SSH client to access your account. PuTTY works fine for me (free download, search for it). Type in your site address and press "connect". Username and password are either the same as control panel or as you set them up.
i. Move into your django project directory:
"cd webapps"
"cd django"
"cd myproject" (or whatever your project is called)
ii. Run the command:
python2.4 manage.py syncdb
(the "python2.4" is to run the version of python with Django, rather than the default install on Red Hat linux)
You should be able to import your existing db data by doing a backup of your database (which creates a file with a big SQL statement) and then running the SQL statement on your new database. WebFaction provides phpMyAdmin for MySql which is pretty straightforward to use.
5. FIRING IT UP
Now use an SSH client to access your account. PuTTY works fine for me (free download, search for it). Type in your site address and press "connect". Username and password are either the same as control panel or as you set them up. Move into the apache2 directory
"cd webapps"
"cd django"
"cd apache2"
and type the following command
./start
the response should be:
Started
6. ADMIRE YOUR SITE
Hopefully this all worked more or less and I haven't forgotten any of the crucial steps. To restart your server (necessary after changes to settings.py and other things), use the following command from the apache2 directory:
./restart
the response should be:
Restarted
7. DJANGO ADMIN
To get the Django admin to look nice, you'll need to create a static content directory (see instructions above) called "media" and copy the following directories and files into it:
C:\Python24\Lib\site-packages\django\contrib\admin\media
Last edited by rohan (2007-05-07 20:18:15)
Offline
Thanks rohan - There's no way I could have done this, I think I tried every other page on the internet!
Offline
rohan - Thanks for this. I was able to setup my Django app in just 2 hours which is amazing for a newb like me.
One small piece of advice to add (for other newbs), you may want to put an .htaccess file in your static media dir with a single line "Options -Indexes" without the quotes so nefarious folks can't browse your static files.
Offline
This does not work for me
... I get this error when running: python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 2, in ?
from django.core.management import execute_manager
ImportError: No module named django.core.management
can anyone assist?
Offline
WinterWeaver wrote:
This does not work for me
... I get this error when running: python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 2, in ?
from django.core.management import execute_manager
ImportError: No module named django.core.management
This is because the 'python' command runs python2.4, but the django libraries have been installed for python2.5.
Try this instead:
python2.5 manage.py syncdb
I hope that helps. ![]()
~Chris Sebastian
Offline
Thanks likebike,
python -v returns version 2.51
I have tried to run via python2.3, 2.4 and 2.5 with the same error on all of them
I also noticed that my ~/lib/python* folders are empty, no django apps in there at all, is this how it should be?
any ideas?
ps: this is my first time using web faction, and first time hosting my own web app framework, so there are many concepts which is quite new for me.
I've also been through the screencast, and I have the same problem.
When asked to run django-admin syncdb. this also does not work, just get a command not found error.
Offline
I've also tried to remove the Django app, and then re-install it... same problem.
Offline
I seemed to have solved the problem.
I created a symlink in ~/lib/python2.5 that points to ~/webapps/django/lib/django
Offline
Hello WW,
Thanks tons. I was getting the same error and the simlink suggested by you worked.
Balaji
Offline
For the symlink, the Django install docs say:
ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django
So, for Webfaction, do I type this?
ln -s `pwd`/home/<username>/lib/python2.5 /home/<username>/webapps/<app-name>/lib/django
(I don't want to inadvertently screw anything up...)
Offline
I did more googling and gave the symlink a try anyway, but I still get an error.
I checked out the latest version of django directly to:
/home/username/webapps/appname/lib/django
When I move into the application directory (where manage.py lives) and type "python2.5 manage.py validate", I get an error:
[agovella@web31 babel]$ python2.5 manage.py validate
babel.bands: __init__() got an unexpected keyword argument 'max_length'
babel.places: __init__() got an unexpected keyword argument 'max_length'
babel.events: __init__() got an unexpected keyword argument 'max_length'
3 errors found.
When I type "python2.5 manage.py --version" it tells me I'm still using django 0.96.
How do I make sure it's pointing to the right version of django? (And can I remove the old version?)
Offline
Turns out python wa using the django under lib/python2.5 instead of under myprojcet/lib. I moved the crrect django files there and everything works fine.
Offline
Hi; I want to run my django app at (myhost)/results
so, in Domain/Websites - WebSites, Add,
I give it a name 'django'
pick the IP
Ignore the https checkbox
select www.mydomain.com
Add a site app, linking my django app to url path '/results'
and I get an error, under the subdomain list, that "Value already exists"
This is because I already have a static website at www.mydomain.com, I'm guessing.
So, do I need to link a new sub-domain 'django.mydomain.com' if I don't want to bundle in my static pages?
Thanks, in advance.
Offline
leehinde wrote:
So, do I need to link a new sub-domain 'django.mydomain.com' if I don't want to bundle in my static pages?
No, you don't have to do that. I have just tried to mount your Django app on www.yourdomain.com/results in the control panel and it worked like a charm. I have removed it right after I verified it works. You just have to wait a minute in order for Apache to reconfigure the settings.
I also see you have now set it up on results.yourdomain.com so I presume you want it that way. Whatever you pick, it will work the same...
Regards,
Offline
sime wrote:
leehinde wrote:
So, do I need to link a new sub-domain 'django.mydomain.com' if I don't want to bundle in my static pages?
No, you don't have to do that. I have just tried to mount your Django app on www.yourdomain.com/results in the control panel and it worked like a charm. I have removed it right after I verified it works. You just have to wait a minute in order for Apache to reconfigure the settings.
I also see you have now set it up on results.yourdomain.com so I presume you want it that way. Whatever you pick, it will work the same...
Thanks, perhaps I was too impatient.
Offline
FYI, we have a new guide available at http://docs.webfaction.com/software/django.html
Offline