Talk:Django

PS problem
I'm running a PS server with dreamhost and am getting a mkpath error while doing the easy_install. error: Setup script exited with error: mkpath: 'name' must be a string has anyone else had an issue with this? I think this is directly relating to the PS side of things, but obviously dreamhost isn't helping me on this. These instructions seem relatively useless in helping me figure out how to fix this nor set up on a dreamhost PS. --Wonderfullyrich 09:24, 21 October 2009 (UTC)

Custom Python Problem
I needed to use Python 2.6 for my Django 1.0 site. I had no problems installing either Python or Django and having access to all the great utilities via the command line in my shell. But when I browse to my site through the web it appears my site is using Python 2.4, the default Python implementation on Dreamhost. How do I get my Django site to use the custom version I installed and not the default? --Natantus 08:38, 15 December 2009 (PST)


 * if sys.version < "2.6": os.execl("/path/to/your/copy/of/python2.6", "python2.6", *sys.argv)
 * Note that you'll need your own copies of Django and MySQLdb installed, as these modules are only installed for Python 2.3 and 2.4 on our system. (Nothing personal against newer versions, the release of Debian we're using just doesn't have support for anything newer.) Andrew F 17:56, 15 December 2009 (UTC)


 * Would I place this in the settings.py file for my django project? Thanks for the quick reply! --Natantus 13:50, 16 December 2009 (PST)


 * Nope, settings.py gets loaded too late. Stick it at the top of passenger_wsgi.py (after importing sys and os, of course) -- that's the first thing Passenger loads. Andrew F 22:38, 16 December 2009 (UTC)


 * That's exactly what I needed. Thanks!  Should this info be included in the Python or Django article?  I'm sure it would come in handy for others. --Natantus 14:46, 16 December 2009 (PST)


 * It's already alluded to in Passenger WSGI, but it's probably worth mentioning in Django as well. Go ahead! Andrew F 23:33, 16 December 2009 (UTC)

Test Module
Using the built in Django test utility seems like a great way to check out my installation. However, it requires that I be able to create and delete MySQL databases via command line utilities. Is this just not possible because of the shared database hosting on Dreamhost? I'm basically running this command: python manage.py test I only got it to work once. I created a database through the panel called test_django_mysite_com. When it gave me an error that said the database existed I allowed it to delete the database. After the test was done the database disappeared and now it won't come back for 5 days. Any help on this issue would be great. --Natantus 12:55, 20 December 2009 (PST)


 * Ideally, we'd prefer that you run unit tests on your own computer, rather than on our servers. If you absolutely need to run tests here, though, your best bet is to use the SQLite database backend for tests rather than MySQL. Andrew F 17:52, 21 December 2009 (UTC)

.htaccess
Is it possible to use a .htaccess file together with django? Main reason is hotlinking protection with mod_rewrite rules.

It seems possible with Passenger, but placing the usual .htaccess file in my passenger public directory doesn't work. So either some admin configuration is required or i'm doin it wrong (or it's impossible) Any pointers? --Lajcik 23:18, 3 February 2010 (UTC)


 * I figured it out seconds after posting on the wiki - it works if you place the .htaccess file in the root of your domains web directory where (where your passenger-wsgi.py file goes) --Lajcik 23:23, 3 February 2010 (UTC)

I am running Django 1.4.1 (python 2.7) and I am trying to access the admin interface. The error logs seem to be insisting that I use an .htaccess file, but all of the descriptions I have seen for what should be in this file are related to older versions of Django or asume use of FastCGI instead of Passenger. I've tried using the suggested file on http://www.mochasupport.com/kayako/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=448, but despite the fact that the permissions for the file are -rw-rw-r-- I am still getting the following error: [Mon Oct 08 11:54:01 2012] [crit] [client 99.173.24.58] (13)Permission denied: /home/leahklearman/scan.soundfit.me/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable, referer: http://scan.soundfit.me/admin/ --Klrmn 10:00, 9 October 2012 (PDT)

Script Sometimes Does Not Work
I tried to follow this methodology to install Django, but got an error:

Uh-oh, it looks like your server doesn't have django installed. Ask DreamHost Support to install it for you! [ Executable: /usr/bin/python ]

However, because Django isn't officially supported, you're not actually supposed to ask dreamhost support to install it for you; I asked and they very politely (and quite rightly) refused and pointed me here.

Anyone have any information doing the actual Django install itself? --Aphoenix 18:42, 3 March 2010 (UTC)


 * Support is incorrect in this case; Django is supposed to be installed system-wide, and they should be either installing it on request or asking an admin to do so. Tell them I sent you. Andrew F 19:06, 3 March 2010 (UTC)

Awesome - Thanks Andrew F! i will commence with the name dropping. Though now that I've gotten back to it, I see that I'm no longer getting that error; my 3am deduction abilities tell me that you likely fixed it for me. Thanks! Aphoenix 07:53, 6 March 2010 (UTC)

Pinax Installation with Virtualenv
I'm trying to install a Django based social website called Pinax (http://www.pinaxproject.com). Pinax is essentially a large number of reusable Django apps all rolled together. To make it all work they give you a package that installs a virtualenv with exactly the dependencies needed to get it going, which makes this type of product very powerful. My problem is that I'm unsure how to point at my new virtualenv from my passenger_wsgi.py file. The documentation I got from the pinax site resides here: http://pinaxproject.com/docs/dev/deployment.html?highlight=mod_wsgi

Where do I put the wsgi script and how do I access it? I'd love to write up an article on your wiki about Pinax once I get this thing going. --Natantus 09:05, 17 March 2010 (PST)


 * EDIT: Figured this one out. Took a fair amount of research to find a simple solution already on your wiki.  I'll still write up the Pinax article once I'm finished doing a bit of testing.  Turns out I didn't need to use the wsgi script, which is ok because i'd probably need to sign up for a Private Server to go that route.  --Natantus 18:05, 19 March 2010 (PST)

Django-setup.py on Wiki
I don't think the wiki is the best place for this file, as the wget command brought me the source code of an html page (the wiki page), and things worked better by copying the contents of that page into a cat writing to the setup.py I noticed this after I had "corrected" the capitalization because MediaWiki upper-cases the first letter, and still got an error. Qayshp


 * Was a configuration issue with the wiki -- we used to have a custom rewrite rule for that URL, which was inadvertently lost. Fixed now. Andrew F 16:39, 14 June 2010 (UTC)

PhpMyAdmin not working
I successfully installed Django using these instructions, but now I cannot use phpMyAdmin to view the databases under that domain. Django is installed into and I used mysql. to host the databases. It looks like the phpMyAdmin link in Dreamhost's Control Panel gets forwarded from http://mysql. / to http:// /dh_phpmyadmin/mysql. / . This gets gobbled up by Django and returns a 404.

What's the best way to correct this? --Brousch 19:51, 28 July 2010 (UTC)


 * Create a subdomain of your domain, and hit phpMyAdmin at http://subdomain.example.com/dh_phpmyadmin/mysql.example.com/ -- Andrew F 18:13, 23 July 2010 (UTC)

Thank you, this works fine. I ended up going with mysql.db. --Brousch 19:51, 28 July 2010 (UTC)

I am having the same issue. My mysql is hosted at mysq. but now get a 404. What do I redirect to where? Can you elaborate what you mean by subdomain, example? Subdomain = mysql and example = ? --Executor89

Setup Script fails on Django 1.2.1
The server I'm on (forge) just updated to Django 1.2.1, and now the install script fails after entering the database info:

Checking connection... looks good! Creating project framework... creating passenger_wsgi.py...  customizing settings...  setting permissions...  copying admin media... OK Running manage.py syncdb... Traceback (most recent call last): File "./HalfOfMyLife/manage.py", line 11, in     execute_manager(settings) File "/var/lib/python-support/python2.5/django/core/management/__init__.py", line 438, in execute_manager utility.execute File "/var/lib/python-support/python2.5/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/var/lib/python-support/python2.5/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/var/lib/python-support/python2.5/django/core/management/base.py", line 218, in execute output = self.handle(*args, **options) File "/var/lib/python-support/python2.5/django/core/management/base.py", line 347, in handle return self.handle_noargs(**options) File "/var/lib/python-support/python2.5/django/core/management/commands/syncdb.py", line 52, in handle_noargs cursor = connection.cursor File "/var/lib/python-support/python2.5/django/db/backends/dummy/base.py", line 15, in complain raise ImproperlyConfigured("You haven't set the database ENGINE setting yet.") django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet. oops, manage.py failed!

Setup Script fails on Django 1.4
The static media files for the admin application have moved in Django 1.4. (https://docs.djangoproject.com/en/dev/releases/1.4/)

Warning If you're implicitly relying on the path of the admin static files within Django's source code, you'll need to update that path. The files were moved from django/contrib/admin/media/ to django/contrib/admin/static/admin/.'' You have to edit the script to make this work for 1.4.

django-setup.py Script had me create 2 super users
Not sure if it is an error or not, but... You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'qayshp'): E-mail address: qayshp@###.### Password: Password (again): Superuser created successfully. Installing index for admin.LogEntry model Installing index for auth.Permission model Installing index for auth.Group_permissions model Installing index for auth.User_user_permissions model Installing index for auth.User_groups model Installing index for auth.Message model No fixtures found. Creating a Django superuser... Username: qayshp Error: That username is already taken. Username: Error: That username is invalid. Use only letters, digits and underscores. Username: admin E-mail address: admin@###.###.### Password: Password (again): Superuser created successfully.

SUCCESS! Your Django application is fully set up - enjoy! I dropped all tables and removed all files created just to retry it, this time entering a username instead of letting it default to mine... same thing.

I cleaned up and ran the script again, this time entering 'no' when prompted if I wanted to create a superuser... it still prompted me to create a user, but only one this time. Just thought it was noteworthy

DJango Tutorial Tips
Are you going through the DJango tutorials? Here's some helpful advice.
 * 1)  Upon finishing the dreamhost setup wizard- go to http://yoursite.com/    you should get a django 404 message.
 * 2)  Don't run manageserver.py runserver (this is against DH policy and you'll get an alert telling you the same- but the alert will arrive in 8 hours or so).
 * 3)  if you go to http://yoursite.com/admin/ you should get the admin server but I don't (i'm troubleshooting and if I can solve it or if anyone else can - please feel free to  update this section)

So the problem is that there is no default page setup, so when you go to your domain, Django has no rule to say "Show this page" it only has rules for 'admin' and 'admin/docs'. "but these don't work either". That is true and we can fix that, BUT only by creating a default page, you can't get both "welcome screen" and "Admin" working at once (or atleast i can't).

To get the proper 'welcome" screen after installing

 * 1) To stop getting a 404 after following the tutorial, edit the 'urls.py' and comment out '(r'^admin/doc/', include('django.contrib.admindocs.urls')),' and '(r'^admin/', include(admin.site.urls)),'.

To get the Admin docs area working

 * 1) If you followed the step above to get the welcome screen going and you want to get the admin working:
 * 2) * To get 'http://yoursite.com/admin/' working, uncomment ' 'django.contrib.admin',' from the bottom of the settings.py.
 * 3) * From 'urls.py', make sure '(r'^admin/', include(admin.site.urls)),' isn't commented out (Even though I told you to comment it out before, that was to get the 404 working).
 * 4) * For the docs:
 * 5) **un comment '(r'^admin/doc/', include('django.contrib.admindocs.urls'))' from urls.py.
 * 6) **Add "'django.contrib.admindocs'," to the 'INSTALLED_APPS' array.
 * 7) You will now notice the 'welcome screen' doesn't work. That is because you have you pages built yet.

If you can't use manageserver.py runserver
If you can't use manageserver.py runserver then how do you get the "Welcome to Django" page described in the tutuorial ? I tried to just forge ahead, but I'm getting an "ImportError" on the hello world example, which I suspect is related.

Augustfirst 15:35, 22 December 2010 (PST)

Script Error Breaks Installation
I received the following error (domain details changed to protect the innocent):

... (lots of preliminary stuff removed) ... What would you like to name your project? >> xyz An excellent name! You'll need a database for your Django project. If you don't already have one ready, you can create one from the DreamHost Panel at: https://panel.dreamhost.com/index.cgi?tree=goodies.mysql MySQL hostname: mysql.xyz.com Database name: djangodb MySQL username: django and password: 12345 Checking connection... looks good! Creating project framework... oops, django-admin failed to run!

This is a result of a file path in the script pointing to the wrong place. To correct this:
 * 1) On the command line, type: emacs django-setup.py (or use any other editor that shows line numbers)
 * 2) Scroll down to line 126
 * 3) Change "/usr/bin/django-admin" to "/usr/bin/django-admin.py"
 * 4) Save and exit: -x, -s, -x, -c

Run the script again. It should work now.

Does anyone know who to contact to get the actual script updated?

--

I second this. I'm on the server "angels" and my django is still hanging back at 1.2.1, as of February 28, 2012. The django setup script failed for the reason above, but I just went and did what the script said manually, as faithfully as I could. Unfortunately I've now run into other problems that have me pulling my hair out (dealt with elsewhere) and I can't shake the feeling that it's due to a wacky set of version mismatches. --joeycarr

-- Blog post here claims to fix problem. Brianckeegan (talk) 13:26, 14 August 2012 (PDT)

Static Media
The Django 1.2 docs provide info on hosting static files for development using a generic view. The WSGI docs show an example for what to do if you have free run of your httpd.conf. Unfortunately neither of these is satisfactory for the dreamhost user. What would be the best route for us? A subdomain to handle all the media would be possible, but it doesn't seem quite right. --joeycarr Feb 28, 2012

OF COURSE, after two hours of struggle, as soon as you post about it you figure it out in two minutes. The default configuration takes care of serving static media from the public directory. Because of a breakage in the setup-django.py script under the django 1.2.1 environment on my server, I managed to copy all of my admin media un-dereferenced, i.e. as symlinks, so I was getting 404s masking 403 forbidden errors due to the symlinks. If you can't be a shining example, at least you can be a dire warning. --joeycarr Feb 28, 2012.

Script Usefulness
What does this script do that django-admin does not do besides writing the passenger_wsgi.py? Seems absolutely useless to me and the wiki mentions nothing about how to actually setup the passenger_wsgi.py for those that have setup their django projects elsewhere and do not wish to use this script to do that yet again.