Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm working on a silly weekend project called, "The Best Picture" as a method of getting into Django again. I have TheBestPicture as the project, then apps for uploading, voting, and doing user management. These all share several common classes, notably Picture, Vote, and User. Where should I define models for these classes so that they are accessible to all the applications in the project?

I hate to decide arbitrarily to put it in the Picture, Vote, or User apps, so I dumped the .py files for the objects in the main folder along with settings and the like. This is probably not the best idea since now the interpreter throws a poo poo fit if I do, Picture.objects.all().

tl;dr: Where should I define a model used across several applications in a project?

EDIT:
code:
INSTALLED_APPS = (
	'django.contrib.admin',
	'django.contrib.auth',
	'django.contrib.contenttypes',
	'django.contrib.sessions',
	'django.contrib.sites',
	'TheBestPicture.uploader',
	'TheBestPicture.Picture.Picture',
	'TheBestPicture.Vote.Vote',
)

Jo fucked around with this message at 01:16 on Aug 8, 2009

Adbot
ADBOT LOVES YOU

nbv4
Aug 21, 2002

by Duchess Gummybuns
If you have a single model that needs to be a lot of places, you can put it in it's own app, and just import it everywhere you use it ("from picture.models import Picture"). Or if you have a bunch of models which are used all over the place, you can do what I do and just put them all in one app called "main", then instead of

code:
from picture.models import Picture
from profile.models import Profile
from foo.models import Foo
you can just do

code:
from main.models import *
The only problem with this is that if you have a lot of views relating to these ubiquitous models, your views.py will get pretty unwieldy.

Theres actually a bug in django (that hasn't been fixed as of a few weeks ago at least), where django will poo poo itself if you define a model like this:

code:
class MyModel(models.Model):
    user = models.ForeignKey("django.contrib.auth.User")
    picture = model.ForeignKey("picture.Picture")
You have to do it like this:
code:
from django.contrib.auth.models import User
from picture.models import Picture

class MyModel(models.Model):
    user = models.ForeignKey(User)
    picture = model.ForeignKey(Picture)
...which makes going hog wild with making everything in seperate apps kind of difficult.

Jo
Jan 24, 2005

:allears:
Soiled Meat

nbv4 posted:

Words.

Awesome. Thank you! :3:

NerftheSmurf
Jun 13, 2003

I will smurf you
Anyone have any experience with using Django with Google App Engine? For my first Django app, I'm writing a small webapp for my company. With app-engine-patch it's not too bad, as I get the admin interface, which was really great in selling my boss/coworkers on the project who otherwise couldn't care less about python webapps. Also it's completely free, which is nice in lean times.

Working around some of the datastore limitations can be a bit annoying but overall it's been pretty alright.

king_kilr
May 25, 2007

NerftheSmurf posted:

Anyone have any experience with using Django with Google App Engine? For my first Django app, I'm writing a small webapp for my company. With app-engine-patch it's not too bad, as I get the admin interface, which was really great in selling my boss/coworkers on the project who otherwise couldn't care less about python webapps. Also it's completely free, which is nice in lean times.

Working around some of the datastore limitations can be a bit annoying but overall it's been pretty alright.

You also might want to look at: http://code.google.com/p/google-app-engine-django/ no idea if it's better or worse, but I know one of the devs :)

nbv4
Aug 21, 2002

by Duchess Gummybuns
Is anyone here able to get django_cropn and django-tagging to work in 1.1? I can get tagging to work, but if I try to register the Model with the tagging app, I get a "Can't Adapt" error whenever I try to add a new instance of that model. I wrote this up on the django group, but I got no response: http://groups.google.com/group/django-users/browse_thread/thread/68e58977b46d08bd/f7ce9ec1b56ef8a2?lnk=gst&q=nbv4#f7ce9ec1b56ef8a2

And In django_cron, I get this error when I try to run syncdb when "django_cron" is in my INSTALLED APPS":
code:
Traceback (most recent call last):
  File "/home/chris/Websites/fanmarkers/manage.py", line 11, in <module>
    execute_manager(settings)
  File "/home/chris/lib/python2.6/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/home/chris/lib/python2.6/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/chris/lib/python2.6/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/chris/lib/python2.6/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/home/chris/lib/python2.6/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/chris/lib/python2.6/django/core/management/commands/syncdb.py", line 52, in handle_noargs
    tables = connection.introspection.table_names()
  File "/home/chris/lib/python2.6/django/db/backends/__init__.py", line 483, in table_names
    return self.get_table_list(cursor)
  File "/home/chris/lib/python2.6/django/db/backends/postgresql/introspection.py", line 30, in get_table_list
    AND pg_catalog.pg_table_is_visible(c.oid)""")
psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
Has anyone gotten these apps to work, or should I just give up and move on?

ijustam
Jun 20, 2005

I need some ideas on how to populate an HTML table. This is what happens:

1) A driver is given a shift (a position number) for a day (done in the admin panel)
2) That number needs to be placed on a table, like so:



This is what I have: http://parkrrr.net/bus/schedule/

I'm a bit lost as to how to synchronize the cells. I'm really quite lost on this so any help would be appreciated.

Hanpan
Dec 5, 2004

Wow, this is driving me crazy, I hope someone can help.

I am trying to use the dev server to serve up images from my media folder, and nothing I do seems to work. Here is how my settings.py looks:

code:
MEDIA_ROOT = os.getcwd() + '/media/'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/'
And my urls.py is setup like so:

code:
urlpatterns = patterns('',
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.getcwd() + '/media/'}),
    (r'^admin/', include(admin.site.urls))
)
Now, if I type http://localhost:8000/media/uploads/image.jpg (which does exist in the file system for definite), it gives me a page which says "Page not found: /media/uploads/image.jpg".

I have definitely imported os in both settings.py and urls.py and I am sure this is something simple. Please help!

king_kilr
May 25, 2007
You can't have ADMIN_MEDIA_PREFIX and MEDIA_ROOT be the same.

Hanpan
Dec 5, 2004

Man do I feel stupid. Thanks very much.

Hanpan
Dec 5, 2004

I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible.

It seems to me the best way to do this would be to create a custom field type, so I could do something like this in my model:

image_tb = models.CustomImageField("Thumbnail Image", upload_to ='uploads/projects', size=(50, 50), compression="60", watermark="path/to/watermark.png")

Firstly, I have absolutely no idea if this is the best way of doing things. Is it easier to create a custom field or perhaps hijack the save method? If it is the best method, does anyone have any really simple examples of creating a custom field? Most of the stuff online is incredibly complicated.

Secondly, if I was to create a custom field, is there a way to extend ImageField so I don't have to mess with the admin panel code and keep the core functionality in place?

Would really appreciate any help.

No Safe Word
Feb 26, 2005

Hanpan posted:

I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible.

It seems to me the best way to do this would be to create a custom field type, so I could do something like this in my model:

image_tb = models.CustomImageField("Thumbnail Image", upload_to ='uploads/projects', size=(50, 50), compression="60", watermark="path/to/watermark.png")

Firstly, I have absolutely no idea if this is the best way of doing things. Is it easier to create a custom field or perhaps hijack the save method? If it is the best method, does anyone have any really simple examples of creating a custom field? Most of the stuff online is incredibly complicated.

Secondly, if I was to create a custom field, is there a way to extend ImageField so I don't have to mess with the admin panel code and keep the core functionality in place?

Would really appreciate any help.
Yes, there is, and while I don't know of anything specifically to do what you want, there are all sorts of image-related snippets that are probably either what you want or "close enough" to borrow from:

http://www.djangosnippets.org/tags/image/

king_kilr
May 25, 2007

Hanpan posted:

I want to expand on the ImageField functionality of django. Mainly, I want to check the dimensions of the image the user is upload, and resize / crop where appropriate. I would also like to set compression amount, and perhaps even allow for watermarking. I know there are several libraries out there that do this, but I want to keep it as lightweight as possible.

It seems to me the best way to do this would be to create a custom field type, so I could do something like this in my model:

image_tb = models.CustomImageField("Thumbnail Image", upload_to ='uploads/projects', size=(50, 50), compression="60", watermark="path/to/watermark.png")

Firstly, I have absolutely no idea if this is the best way of doing things. Is it easier to create a custom field or perhaps hijack the save method? If it is the best method, does anyone have any really simple examples of creating a custom field? Most of the stuff online is incredibly complicated.

Secondly, if I was to create a custom field, is there a way to extend ImageField so I don't have to mess with the admin panel code and keep the core functionality in place?

Would really appreciate any help.

Checkout sorl-thumbnail, it probably has everything you want in it: http://thumbnail.sorl.net/docs/

MonkeyMaker
May 22, 2006

What's your poison, sir?
I'm trying to use Django's formsets and having nothing but problems. Here's my current code for the validation/save view:

code:
def update_schedule(request):
    if request.method == 'POST':
        periods = Period.objects.filter(
            user=request.user).order_by('start_time')
        initial_periods = []
        for period in periods:
            initial_periods.append({
                'start_time': period.start_time,
                'end_time': period.end_time,
                'name': period.name,
                'empty': period.empty
            })
        PeriodFormSet = formset_factory(UpdatePeriodForm)
        formset = PeriodFormSet(request.POST, initial=initial_periods)
        if formset.is_valid():
            for form in formset.cleaned_data:
                if form:
                    if not form in formset.deleted_forms:
                        period, created = Period.objects.get_or_create(
                            user = request.user,
                            start_time = form['start_time'],
                            end_time = form['end_time'],
                            name = form['name'],
                            empty = form['empty']
                        )
                        if created:
                            period.save()
                else:
                    pass
            request.notifications.add('saved')
            return HttpResponseRedirect('/accounts/profile/update')
        else:
            request.notifications.add(formset.errors.__str__())
            return HttpResponseRedirect('/accounts/profile/update')
I get an error of: 'UpdatePeriodFormFormSet' object has no attribute 'deleted_forms'. I know that I've passed in a 'deleted form' since I see this: u'form-2-DELETE': [u'on'] in the request object.

Any ideas?

nbv4
Aug 21, 2002

by Duchess Gummybuns
Whoa whoa whoa, you know you can just give a formset a queryset and be done with it.

code:
peroids = Peroid.objects.filter(user=request.user)
PeroidFormset = modelformset_factory(Peroid)
formset = PeroidFormset(queryset=peroids)
then when you want to save it, you can just do:

code:
peroids = Peroid.objects.filter(user=request.user)
PeroidFormset = modelformset_factory(Peroid)
formset = PeroidFormset(request.POST, queryset=peroids)

if formset.is_valid():
    formset.save()
...aaaand your done

spencer for hire
Jan 27, 2006

we just want to dance here, someone stole the stage
they call us irresponsible, write us off the page
Anyone have experience customizing the comments framework?

I followed the doc on this page http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/

but I can't figure out to render my new CommentFormWithTitle. The documentation is kind of sparse (or this is way out of my league to be messing around with).

MonkeyMaker
May 22, 2006

What's your poison, sir?

nbv4 posted:

Whoa whoa whoa, you know you can just give a formset a queryset and be done with it.

code:
peroids = Peroid.objects.filter(user=request.user)
PeroidFormset = modelformset_factory(Peroid)
formset = PeroidFormset(queryset=peroids)
then when you want to save it, you can just do:

code:
peroids = Peroid.objects.filter(user=request.user)
PeroidFormset = modelformset_factory(Peroid)
formset = PeroidFormset(request.POST, queryset=peroids)

if formset.is_valid():
    formset.save()
...aaaand your done

Hey, thanks for this. It didn't actually solve my problem, but it pointed me at inlineformset, which did.

Jo
Jan 24, 2005

:allears:
Soiled Meat
Argh. I can't figure out why this is happening. I save an object and it doesn't show up in TheModel.objects.all():

code:

In [5]: apt = Appointment.objects.create( dateAndTime = datetime(2009,8,25,12,45), advisorAbbreviation='CP' )

In [6]: apt
Out[6]: <Appointment: Appointment with , at 2009-08-25 12:45:00>

In [7]: apt.save()

In [10]: apt
Out[10]: <Appointment: Appointment with , at 2009-08-25 12:45:00>

In [11]: Appointment.objects.all()
Out[11]: []

--- Also ---

In [7]: apt = Appointment( dateAndTime = dt( 2009, 8, 25, 12, 0 ), advisorAbbreviation='CP' )

In [8]: apt.save()

In [9]: Appointment.objects.all()
Out[9]: []

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
By any chance have you overridden the save method on your Appointment model without calling super(Appointment, self).save() ?

Jo
Jan 24, 2005

:allears:
Soiled Meat

jupo posted:

By any chance have you overridden the save method on your Appointment model without calling super(Appointment, self).save() ?

Not that I'm aware.

code:
class Appointment( models.Model ):
	"""Stores a single appointment."""

(These CHOICES removed to protect the innocent.)

	slotOpen = models.BooleanField()
	advisor = models.CharField( max_length=2, choices=ADVISOR_CHOICES )
	datetime = models.DateTimeField( primary_key=True, unique=True )
	user = models.CharField( max_length=8 )
	firstName = models.CharField( max_length=100 )
	lastName = models.CharField( max_length=100 )
	email = models.CharField( max_length=200 )
	reason = models.TextField()
	status = models.CharField( max_length=2, choices=YEAR_IN_SCHOOL_CHOICES )

	def __init__( self, advisorAbbreviation, dateAndTime ):
		self.slotOpen = True
		self.advisor = advisorAbbreviation
		self.datetime = dateAndTime
		self.user = ""
		self.firstName = ""
		self.lastName = ""
		self.email = ""
		self.reason = ""
		self.status = "NA"

	def __unicode__( self ):
		return "Appointment with " + self.lastName + "," + self.firstName + " at " + str(self.datetime)

nbv4
Aug 21, 2002

by Duchess Gummybuns

Jo posted:

Not that I'm aware.

code:
class Appointment( models.Model ):
	"""Stores a single appointment."""

(These CHOICES removed to protect the innocent.)

	slotOpen = models.BooleanField()
	advisor = models.CharField( max_length=2, choices=ADVISOR_CHOICES )
	datetime = models.DateTimeField( primary_key=True, unique=True)
	user = models.CharField( max_length=8 )
	firstName = models.CharField( max_length=100 )
	lastName = models.CharField( max_length=100 )
	email = models.CharField( max_length=200 )
	reason = models.TextField()
	status = models.CharField( max_length=2, choices=YEAR_IN_SCHOOL_CHOICES )

	def __init__( self, advisorAbbreviation, dateAndTime ):
		self.slotOpen = True
		self.advisor = advisorAbbreviation
		self.datetime = dateAndTime
		self.user = ""
		self.firstName = ""
		self.lastName = ""
		self.email = ""
		self.reason = ""
		self.status = "NA"

	def __unicode__( self ):
		return "Appointment with " + self.lastName + "," + self.firstName + " at " + str(self.datetime)

Try getting rid of the __init__ part. I think you may be overwriting something that is required. You can use the default kwarg in your model class to achieve what you want. like this:

code:
class Appointment( models.Model ):
	"""Stores a single appointment."""

(These CHOICES removed to protect the innocent.)

	slotOpen = models.BooleanField(default=True)
	advisor = models.CharField( max_length=2, choices=ADVISOR_CHOICES, default="whatever")
	datetime = models.DateTimeField( primary_key=True, unique=True )
	user = models.CharField( max_length=8 )
	firstName = models.CharField( max_length=100 )
then the rest of the functionality you are after is already built into the default model init:

Appointment(advisor="MyAdvisorAbbreviation", datetime="whatever")

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
I was on the right track, technically the problem is you're not calling __init__ on the super class, but nbv4 is right in that you don't need any of that stuff there at all.

Hanpan
Dec 5, 2004

Another absolutely retarded question:

Is there a way to exclude fields form a query set? I am putting my result straight into JSON, and I am I trying to exclude a "tags" ManyToMany field from my model since I don't need it and it will hit the database unnecessarily. I have tried this:

code:
projects = Projects.objects.category(slug).exclude(tags)
But obviously it doesn't work. Is there a way to do this?

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

Hanpan posted:

Another absolutely retarded question:

Is there a way to exclude fields form a query set? I am putting my result straight into JSON, and I am I trying to exclude a "tags" ManyToMany field from my model since I don't need it and it will hit the database unnecessarily. I have tried this:

code:
projects = Projects.objects.category(slug).exclude(tags)
But obviously it doesn't work. Is there a way to do this?

http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields

code:
projects = Projects.objects.category(slug).values()

Jo
Jan 24, 2005

:allears:
Soiled Meat

nbv4 posted:

:words:

jupo posted:

:words:

Thank you for the responses. If it works, I will love you fo evah.

Edit: It works. :dance:

Jo fucked around with this message at 22:11 on Aug 28, 2009

Threep
Apr 1, 2006

It's kind of a long story.
I've been teaching myself django slowly by using it to make web interfaces for my various maintenance scripts and I'd like to hear what the best practice is for solving the following problem.

I'm trying use SQLite full text search from django. I've been googling around and couldn't find anyone else doing it properly, most just used raw SQL statements or other database engines.

SQLite's full text search implementation works via a special table that just maps search results to ids. That's not important, as the table isn't updated from django. If I need to do so I'll just use signals or make a SearchableModel subclass that overrides save().

The actual search is where I'm not sure how to do it best. Right now I've made a complex filter class that hacks in the required join (I don't know how to force a join in a good way) and adds the 'WHERE search_table.content MATCH ' + searchstring clause to the QuerySet.

That's obviously not pretty and it's also vulnerable to injections, so is there a better way to extend QuerySet functionality?

It hit me while writing this that I could add the search table as a managed table with a foreign key for the main table and then add support for a __match operator in the db backend, could I do this in a reusable way?

Edit: I switched to Postgres and patched django-fts to suit my needs but if anyone else wants to do this with SQLite it's much easier to patch into django 1.1 than 1.0

Threep fucked around with this message at 22:09 on Sep 1, 2009

checkeredshawn
Jul 16, 2007

I have to move my Django app over from Linux to Windows, and I'm having trouble serving up the admin media. The lines that are related to the issue are probably the following:

From Apache httpd.conf:

code:
<Directory "C:/Python25/Lib/site-packages/django/contrib/admin/media/"> 
    AllowOverride None 
    Options None 
    Order allow,deny 
    Allow from all 
</Directory> 

Alias /media/ "C:/Python25/Lib/site-packages/django/contrib/admin/media/"

<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonOption django.root /mysite
    PythonDebug On
</Location>
From settings.py:

code:
MEDIA_ROOT = "C:/Python25/Lib/site-packages/django/contrib/admin/media/"
MEDIA_URL = 'http://localhost/media/'
ADMIN_MEDIA_PREFIX = '/media/'
When I go to http://localhost/admin it shows the admin interface with no styling so I figured it must be an issue with serving up the media. Anyone have any ideas?

jupo
Jun 12, 2007

Time flies like an arrow, fruit flies like a banana.
Try this

code:
<Location "/media/">
    SetHandler None
</Location>  
You'll also want to point settings.MEDIA_ROOT to the media directory for your project, not django.

nbv4
Aug 21, 2002

by Duchess Gummybuns
Also, try changing the media URL for your site to something other than http://localhost/media. You can't have admin media teh samne as regular media.

checkeredshawn
Jul 16, 2007

jupo posted:

Try this

code:
<Location "/media/">
    SetHandler None
</Location>  
You'll also want to point settings.MEDIA_ROOT to the media directory for your project, not django.

But if settings.MEDIA_ROOT is pointing at django/contrib/admin/media, would the admin media work? I figured since the project has no media, I would just point that at the admin media directory. If I made my own media directory, would I have to put the admin media in there?

Also, I tried your suggestion out and it still doesn't work. Now I'm going to make a media directory inside my project and point MEDIA_ROOT at that.

Edit: With the new Location section that you suggested, should I still have the Alias /media/ line in there?

Edit again: So I added a clause to my urls.py that says if the settings file has DEBUG set to True, then have django serve the media files, and the admin media started working properly. Does this mean it's an issue with my Apache config?

Another edit...: I have a Directory statement in my Apache config pointing to my project's media directory. If I take it out of the config, even with that statement in the urls.py and DEBUG set to True, Django does not serve the admin media. I'm confused about why that is. Also, I'm getting TemplateDoesNotExist errors in my Apache error log when going to http://localhost:/admin

checkeredshawn fucked around with this message at 16:20 on Sep 3, 2009

bosko
Dec 13, 2006
MEDIA_ROOT is used for Django-uploaded files. You don't really use it to tell Django where your media is located. You do use MEDIA_URL as a way to use the {{ MEDIA_URL }} variable throughout your templates though.

Basically, to serve media from Apache you need to tell Apache to ignore your media directory as non-Python code, e.g:

code:
<Location "/media">
    SetHandler None
</Location>
At this point, you should have a `media` directory in your projects root. If it is not in your projects root, your best bet is to usually alias the media to somewhere else. So within your project root, create a symbolic link named `media` to wherever you are placing it.

Basically, when it comes down to it the MEDIA_ROOT variable is not used at all to serve media, just for upload paths. Apache/nginx/the Django devserver is in charge of serving the media by setting up the correct paths.

checkeredshawn
Jul 16, 2007

bosko posted:

MEDIA_ROOT is used for Django-uploaded files. You don't really use it to tell Django where your media is located. You do use MEDIA_URL as a way to use the {{ MEDIA_URL }} variable throughout your templates though.

Basically, to serve media from Apache you need to tell Apache to ignore your media directory as non-Python code, e.g:

code:
<Location "/media">
    SetHandler None
</Location>
At this point, you should have a `media` directory in your projects root. If it is not in your projects root, your best bet is to usually alias the media to somewhere else. So within your project root, create a symbolic link named `media` to wherever you are placing it.

Basically, when it comes down to it the MEDIA_ROOT variable is not used at all to serve media, just for upload paths. Apache/nginx/the Django devserver is in charge of serving the media by setting up the correct paths.


I've got a media directory in my project's root, which contains a folder called "admin" with all the admin media, but it still isn't working out. Could it have something to do with my sticking my project in C:\Python25 so that it would be on the python path? I was having issues with Apache when I was trying to declare PythonPath to contain my project's directory, so I just threw it in C:\Python25 and it started working.

Edit: Okay, I put the media directory in the DocumentRoot folder, and now it works. Thanks for all the help everyone. I even moved the project out of C:\Python25 into a different directory (C:\django) and got the PythonPath thing working (I think it was because I had PythonPath "['C:\django'] + sys.path" as opposed to "[r'C:\django'] + sys.path", note the lowercase r in there).

checkeredshawn fucked around with this message at 21:21 on Sep 3, 2009

LOLLERZ
Dec 9, 2003
ASK ME ABOUT SPAMMING THE REPORT FORUM TO PROTECT ~MY WIFE'S~ OKCUPID PERSONALS ANALYSIS SA-MART THREAD. DO IT. ALL THE TIME. CONSTANTLY. IF SHE DOESN'T HAVE THE THREAD, SHE'LL WANT TO TALK TO ME!
This is kind of an Apache/WSGI problem, but I'm trying to deploy Django, and I thought maybe someone here would have seen this before:

I'm on WinXP and when I run net start apache I get the following error message in Event Viewer:
code:
The Apache service named  reported the following error:
>>> httpd.exe: Syntax error on line 3 of 
C:/Program Files/Apache2.2/conf/httpd.conf: 
Cannot load C:/Program Files/Apache2.2/modules/mod_wsgi.so
into server: The specified module could not be found.
For reference, the relevant part of my httpd.conf is
code:
ServerRoot "C:/Program Files/Apache2.2"
Listen 80
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
I think it's some kind of permissions issue, but I can't figure out how to prove that.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

LOLLERZ posted:

This is kind of an Apache/WSGI problem, but I'm trying to deploy Django, and I thought maybe someone here would have seen this before:

I'm on WinXP and when I run net start apache I get the following error message in Event Viewer:
code:
The Apache service named  reported the following error:
>>> httpd.exe: Syntax error on line 3 of 
C:/Program Files/Apache2.2/conf/httpd.conf: 
Cannot load C:/Program Files/Apache2.2/modules/mod_wsgi.so
into server: The specified module could not be found.
For reference, the relevant part of my httpd.conf is
code:
ServerRoot "C:/Program Files/Apache2.2"
Listen 80
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
I think it's some kind of permissions issue, but I can't figure out how to prove that.

Silly question but does the file exist?

bosko
Dec 13, 2006
I'm 99% sure mod_wsgi does not come standard on Apache installs so he probably needs to install the module seperately. Not very familiar with Windows installation but this seems to be a good writeup:

http://code.google.com/p/modwsgi/wiki/InstallationOnWindows

LOLLERZ
Dec 9, 2003
ASK ME ABOUT SPAMMING THE REPORT FORUM TO PROTECT ~MY WIFE'S~ OKCUPID PERSONALS ANALYSIS SA-MART THREAD. DO IT. ALL THE TIME. CONSTANTLY. IF SHE DOESN'T HAVE THE THREAD, SHE'LL WANT TO TALK TO ME!

deimos posted:

Silly question but does the file exist?
That's a perfectly reasonable question, but yes, I have the correct file for my major/minor version of Python, and for my install of Apache, and it's named correctly. It's in the same location as all the other mod_whatever.so files.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

LOLLERZ posted:

That's a perfectly reasonable question, but yes, I have the correct file for my major/minor version of Python, and for my install of Apache, and it's named correctly. It's in the same location as all the other mod_whatever.so files.

well if you renamed it to mod_wsgi.so and placed it in the right directory then check windows permissions for the other .so files and compare it to your mod_wsgi.so

LOLLERZ
Dec 9, 2003
ASK ME ABOUT SPAMMING THE REPORT FORUM TO PROTECT ~MY WIFE'S~ OKCUPID PERSONALS ANALYSIS SA-MART THREAD. DO IT. ALL THE TIME. CONSTANTLY. IF SHE DOESN'T HAVE THE THREAD, SHE'LL WANT TO TALK TO ME!

deimos posted:

well if you renamed it to mod_wsgi.so and placed it in the right directory then check windows permissions for the other .so files and compare it to your mod_wsgi.so
It appears to be identical to the other files (judging by the setting in the "security" tab in the properties dialog).

JammyB
May 23, 2001

I slept with Mary and Joseph never found out
I'm looking for a little advice on deploying some Django websites to an Ubuntu Server. Where exactly should each website live within the file structure? It seems wrong to put everything under my home folder. I realise there are probably lots of ways to do it, so is there any best practice? Similarly, is there any best practice for structuring the website and associated files?

At the moment I've got everything organised on my desktop computer like this:

code:
~/Dev/Django/Django-1.1
~/Dev/Django/example.com/website (the Django project)
~/Dev/Django/example.com/templates
~/Dev/Django/example.com/media
etc...
example.com is also under Mercurial source control. My hope for the future is to have a few different websites running on my server and to be able to use Mercurial's SSH push/pull to do updates when required. I will keep any development work on my desktop or test server.

On the actual server, I imagine I want to apt-get Django rather than install it manually like I've done here. It was a few months ago and I'm not really sure why I did that.

I'm also slightly concerned about whether my current structure is sensible for code reuse. I like to keep each website together for organisation and backup purposes but I'm sure I can adjust if this is a silly way to go about it.

Any advice would be very much appreciated.

Adbot
ADBOT LOVES YOU

MonkeyMaker
May 22, 2006

What's your poison, sir?

JammyB posted:

I'm looking for a little advice on deploying some Django websites to an Ubuntu Server.

This is one of the best guides I've read. Only thing I'd change is using virtualenvwrapper along with virtualenv. Oh, and I usually use MySQL instead of PostgreSQL.

http://lethain.com/entry/2009/feb/13/the-django-and-ubuntu-intrepid-almanac/

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply