A Small Orange Forums: Django problem - A Small Orange Forums

Jump to content

NOTICE: This is *not* an official support forum

All support requests should be made by through our Support Desk or by emailing help@asmallorange.com.
  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Django problem Rate Topic: -----

#1 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 09 December 2006 - 04:32 PM

I am having a problem getting Django working after trying many alternatives based on this forum and the wiki and the instructions on Django site.

I have successfully installed Django files and created a project, database and edited the model files based on the Django tutorial usign the python interpreter. However, when I try to access the site I have been unsuccesful.

Based on the Django site I have the following mysite.fcgi file, where username is my username.
#!/usr/bin/python
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/username/django_src")
sys.path.insert(0, "/home/username/django_projects")

# Switch to the directory of your project. (Optional.)
# os.chdir("/home/username/django_projects/mysite")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "mysite.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")


When I go to http://mydomain.com/dj/mysite.fcgi I get the error msg that there is an Unhandled Exception. When I execute the commands in the python interpreter the output from the runfastcgi command indciates that there are missing parameters for REQUEST_METHOD, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL.

Any help would be appreciated - Django looks really good and this is quite frustrating (I don't know much about getting this to work in FCGI...)




0

#2 User is offline   cypher543

  • Very Large Orange
  • PipPipPipPipPip
  • Group: Members
  • Posts: 451
  • Joined: 01-August 06

Posted 10 December 2006 - 09:28 AM

Doesn't the URL need a "/" at the end? I recall getting an error from Django when I didn't put a "/" at the end of the URL. Sorry I can't be of more help.

This post has been edited by cypher543: 10 December 2006 - 09:28 AM

Warning: Long periods of exposure to me may cause geekyness.
0

#3 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 10 December 2006 - 01:41 PM

QUOTE(cypher543 @ Dec 10 2006, 8:28 AM) View Post
Doesn't the URL need a "/" at the end? I recall getting an error from Django when I didn't put a "/" at the end of the URL. Sorry I can't be of more help.


Thanks for the comment, but I don't think there should a / after the filename (also tried it and didn't make a difference).

Does anyone have the latest Django (0.95) working on ASO? If you do would appreciate a post with the fcgi script.

0

#4 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 10 December 2006 - 10:36 PM

Well, have made some progress. I am using mysql as the database. After some testing found out that while I can import MySQLdb in the python interpreter without error, simply adding import MySQLdb in a script file produces an error. Adding the path to MySQLdb fixed that problem, and now can successfully load the fcgi and the admin signin of Django. I used the method in the wiki, but modified by adding the path to MySQLdb in the fcgi file as follows (third sys.path statement)
#!/usr/bin/python
import sys
sys.path += ['/home/username/django_src']
sys.path += ['/home/username/django_projects']
sys.path += ['/usr/local/lib/python2.4/site-packages']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
WSGIServer(WSGIHandler()).run()

Just learning python and don't understand why the path needs to be added when it works ok in the interpreter - maybe ASO installs the mysql driver in a non standard place???

And ignore the prior comment - does look like Django wants a final /


0

#5 User is offline   jamstooks

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 29-January 07

Posted 29 January 2007 - 03:31 PM

Thanks Yatla, your post was very helpful.

I am having trouble serving the admin media files though, did you figure out how to do this?

I've tried mod_alias, as they suggest here:
http://code.djangopr...ocs/fastcgi.txt

CODE
Alias /media /home/stookey/django_src/contrib/admin/media
RewriteEngine On
RewriteRule ^admin-media/.* - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]


But it's giving me a 500 error. If I comment out the Alias line things work (but I don't have the admin css and js).

I don't want to copy the whole /~django_src/contrib/admin/media directory over since I'll probably be updating django from time to time...

Any suggestions?

Thanks,
-Ben

This post has been edited by jamstooks: 29 January 2007 - 03:44 PM

0

#6 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 29 January 2007 - 11:33 PM

[quote name='jamstooks' date='Jan 29 2007, 2:31 PM' post='60784']
Thanks Yatla, your post was very helpful.

I am having trouble serving the admin media files though, did you figure out how to do this?

Yes try the following:

My .htaccess file is as follows

RewriteEngine On
RewriteRule ^(css/.*)$ - [L]
RewriteRule ^(images/.*)$ - [L]
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(tinymce/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django2.fcgi)
RewriteRule ^(.*)$ django2.fcgi/$1 [L]


My .fcgi file is named django2.fcgi. Then key is to make a link - as follows so that the admin script can find the files (assuming you've installed the django_src in $HOME/django_src, also adjust the path to your site files if you did not install in the root of the server files)

ln -s $HOME/django_src/django/contrib/admin/media $HOME/public_html/media

In your settings.py file make sure the admin media is set to this path, eg,
ADMIN_MEDIA_PREFIX = '/media/'

Hope that all makes sense.

Good luck - I've found Python to be an excellent language, never did like php very much, and Django is a great framework...every time I need something, it's there - overall a robust framework. I converted a WordPress site over to Django and it works great including a members only area.
0

#7 User is offline   jamstooks

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 29-January 07

Posted 30 January 2007 - 09:37 AM

Thanks! I didn't think to use a symbolic link... that did the trick.

Django is great. So powerful! I'm building applications in an afternoon that took me two weeks with PHP or CMS's like Joomla. I'll never go back. PHP is too slow and Joomla, though great for some things, is just too narrow and doesn't use internet best practices for markup.

Thanks again,
-Ben
0

#8 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 30 January 2007 - 09:22 PM

QUOTE(jamstooks @ Jan 30 2007, 8:37 AM) View Post
Thanks! I didn't think to use a symbolic link... that did the trick.

Django is great. So powerful! I'm building applications in an afternoon that took me two weeks with PHP or CMS's like Joomla. I'll never go back. PHP is too slow and Joomla, though great for some things, is just too narrow and doesn't use internet best practices for markup.

Thanks again,
-Ben


Glad I could help. Agree that Django is powerful and completely flexible, sort of a swiss army knife for web development. IMHO it bests Ruby on Rails at it's own game, and the documentation/tutorials make it easy to learn.

0

#9 User is offline   kemical

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 33
  • Joined: 20-April 04

Posted 03 February 2007 - 08:33 PM

Not really sure what my problem is but python interprets the failures properly (e.g putting a wrong path in), however, when trying to access a correct path as defined in my urls it just spins :

CODE
#!/usr/bin/python
import sys
sys.path += ['/home/kemical/django_src']
sys.path += ['/home/kemical/django_projects']
sys.path += ['/usr/local/lib/python2.4/site-packages']
from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'stokes.settings'
WSGIServer(WSGIHandler()).run()


and my .htaccess
CODE
RewriteEngine On
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(django.fcgi)
RewriteRule ^(.*)$ django.fcgi/$1 [L]


And if i try to use decorators within django its spits out syntax errors, but the same code works on python 2.4.4 blink.gif

Any ideas?
adam stokes, pimp extraordinare.
0

#10 User is offline   yeshuah

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 06-February 07

Posted 07 February 2007 - 11:10 AM

I got django all setup as fa as I can see. I get to the admin login page but then it redericts to the wrong page.

http://www.ideadonor...ngo.fcgi/admin/

works fine but when I enter the usrname and pword I get redricted to

http://www.ideadonor.com/admin/ which doesn't exist. What could be the problem?
0

#11 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 07 February 2007 - 12:42 PM

QUOTE(yeshuah @ Feb 7 2007, 10:10 AM) View Post
I got django all setup as fa as I can see. I get to the admin login page but then it redericts to the wrong page.

http://www.ideadonor...ngo.fcgi/admin/

works fine but when I enter the usrname and pword I get redricted to

http://www.ideadonor.com/admin/ which doesn't exist. What could be the problem?


I had the same problem when first testing Django in a subdirectory. You need to add the subdirectory to the path in the Django rewrite rule in your .htaccess file. See this post
0

#12 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 07 February 2007 - 12:52 PM

QUOTE(kemical @ Feb 3 2007, 7:33 PM) View Post
Not really sure what my problem is but python interprets the failures properly (e.g putting a wrong path in), however, when trying to access a correct path as defined in my urls it just spins :

.....

And if i try to use decorators within django its spits out syntax errors, but the same code works on python 2.4.4 blink.gif

Any ideas?


Can you give abit more info on your python files?
0

#13 User is offline   yeshuah

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 06-February 07

Posted 07 February 2007 - 04:31 PM

QUOTE(yatla @ Feb 7 2007, 6:42 PM) View Post
QUOTE(yeshuah @ Feb 7 2007, 10:10 AM) View Post
I got django all setup as fa as I can see. I get to the admin login page but then it redericts to the wrong page.

http://www.ideadonor...ngo.fcgi/admin/

works fine but when I enter the usrname and pword I get redricted to

http://www.ideadonor.com/admin/ which doesn't exist. What could be the problem?


I had the same problem when first testing Django in a subdirectory. You need to add the subdirectory to the path in the Django rewrite rule in your .htaccess file. See this post



Thanks alot now it seems to be working!
0

#14 User is offline   yeshuah

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 06-February 07

Posted 07 February 2007 - 04:46 PM

Yatla. do you now of something that can be done to speed up the restarting of the fcgi django stuff. Since when I update the differet models(django tutorial on polls) I have to wait quite a bit to see the updates online
0

#15 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 07 February 2007 - 06:41 PM

QUOTE(yeshuah @ Feb 7 2007, 3:46 PM) View Post
Yatla. do you now of something that can be done to speed up the restarting of the fcgi django stuff. Since when I update the differet models(django tutorial on polls) I have to wait quite a bit to see the updates online


It does seem sometimes that it takes a few minutes for the server to realize that there is an updated python file available that should be compiled. It may have to do with caching that AOS does (but I'm just speculating). Sometimes I delete the compiled file (.pyc), then the system has to check for a current .py file to compile. That being said, you really should do development and testing on your local PC and update to the server when you're done.
0

#16 User is offline   Carlin

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 24-February 07

Posted 24 February 2007 - 02:55 PM

I've followed the directions here but I can't seem to get it to work. When I browse to the .fcgi file it just sits there waiting for a response. I checked my error log and its full of these lines:

[Sat Feb 24 15:51:35 2007] [warn] FastCGI: (dynamic) server "/home/carlintj/public_html/rssieve/test.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds


Any ideas?
0

#17 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 02 March 2007 - 07:40 PM

QUOTE(Carlin @ Feb 24 2007, 1:55 PM) View Post
I've followed the directions here but I can't seem to get it to work. When I browse to the .fcgi file it just sits there waiting for a response. I checked my error log and its full of these lines:

[Sat Feb 24 15:51:35 2007] [warn] FastCGI: (dynamic) server "/home/carlintj/public_html/rssieve/test.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds


Any ideas?


Did you make any progress? If not, suggest you post your fcgi file.
0

#18 User is offline   AdamW

  • Tiny Orange
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 23-August 07

Posted 27 August 2007 - 10:23 AM

QUOTE(Carlin @ Feb 24 2007, 3:55 PM) <{POST_SNAPBACK}>
I've followed the directions here but I can't seem to get it to work. When I browse to the .fcgi file it just sits there waiting for a response. I checked my error log and its full of these lines:

CODE
[Sat Feb 24 15:51:35 2007] [warn] FastCGI: (dynamic) server "/home/carlintj/public_html/rssieve/test.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds


Any ideas?


I'm having the same problem. My django project files are in ~/django_projects/myproject/. Here is my django.fcgi file.
CODE
#!/usr/bin/env python

import sys, os
from django.core.servers.fastcgi import runfastcgi

sys.path += ['/home/myusername/django_src']
sys.path += ['/home/myusername/django_projects']
sys.path += ['/usr/local/lib/python2.4/site-packages']

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

runfastcgi(method="threaded", daemonize="false")


This django project works just fine on my test server under mod_python. But it doesn't respond when I use FastCGI. I see the same error messages in my error logs that Carlin sees in his error logs. I have tried the URL both with and without a trailing /. Any help would be appreciated.

Adam
0

#19 User is offline   cypher543

  • Very Large Orange
  • PipPipPipPipPip
  • Group: Members
  • Posts: 451
  • Joined: 01-August 06

Posted 29 September 2007 - 09:56 PM

Anybody have any luck? I followed the tutorial here, but nothing happens when a visit my Django app. sad.gif
Warning: Long periods of exposure to me may cause geekyness.
0

#20 User is offline   yatla

  • Small Orange
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 21-January 06

Posted 01 October 2007 - 09:40 PM

QUOTE(cypher543 @ Sep 29 2007, 9:56 PM) <{POST_SNAPBACK}>
Anybody have any luck? I followed the tutorial here, but nothing happens when a visit my Django app. sad.gif


Yes I have two sites running Django, but it's been more than a year since I dealt with installation and configuration. Haven't had to change configuration items since then, so I would think the earlier notes in this sequence still should be valid...maybe if you gave abit more detail?


0

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users