apache mod_wsgi/nginx config: different behaviors if www pre-pended

2008-11-12 Thread Serdar T.

Can someone offer advice on server deployment headaches involving
apache/mod_wsgi/nginx? I seem to be having two problems:

1) Apache/mod_wsgi correctly serves dynamic content from a test app
(located in a ~/public_html directory) when the url starts with
"www".  But apache reverts to serving the default index.html (out of /
var/www) when the "www" is omitted from the url. I tried tweaking the
ServerAlias configs and even using Rewrite rules, but to no avail.

Ideally, I'd like apache and nginx to rerwite all urls to strip the
leading "www"

My server config and relevant django app files (settings.py and
urls.py) are at http://dpaste.com/90308/
They are an adaptation of the configs from EricFlo's screencast 13
(http://thisweekindjango.com/screencasts/episode/21/django-ground-
episode-13/)

2) In addition, the admin backend doesn't work on the production
server (I get a 404 error) regardless of whether or not I pre-pend the
"www". Apache error logs stated that the sqlite database backend did
not have write permissions, but the 404 errors persisted even after I
added the permissions (chmod 755).

Any suggestions would be greatly appreciated!!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: apache mod_wsgi/nginx config: different behaviors if www pre-pended

2008-11-13 Thread Serdar T.

Thanks for the reply Graham. Since the time I wrote the initial
message, I figured out the problem: I was using nginx as the frontend,
as you point out, and sending requests to apache at 127.0.0.1:8080.
But I hadn't updated my virtualhost file to process requests to that
address.

I made the following change to get the dynamic content served
properly. In /etc/apache2/sites-available/mysite.org

 became 

I figured it out after going back to basics and reading up on what a
reverse proxy is and some of the syntax about nginx. Am I correct to
interpret this deployment style as an nginx server front-end that
servers media (once I configure that correctly) and proxies requests
for dynamic content upstream to apache? That makes sense to me
conceptually based on the config settings, but maybe I'm somehow
confusing things.

Now, on to fixing the serving of media.

Thanks again for the suggestions.

On Nov 12, 7:04 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Nov 13, 6:48 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
>
>
> > Can someone offer advice on server deployment headaches involving
> > apache/mod_wsgi/nginx? I seem to be having two problems:
>
> > 1) Apache/mod_wsgi correctly serves dynamic content from a test app
> > (located in a ~/public_html directory) when the url starts with
> > "www".  But apache reverts to serving the default index.html (out of /
> > var/www) when the "www" is omitted from the url. I tried tweaking the
> > ServerAlias configs and even using Rewrite rules, but to no avail.
>
> > Ideally, I'd like apache and nginx to rerwite all urls to strip the
> > leading "www"
>
> > My server config and relevant django app files (settings.py and
> > urls.py) are athttp://dpaste.com/90308/
> > They are an adaptation of the configs from EricFlo's screencast 13
> > (http://thisweekindjango.com/screencasts/episode/21/django-ground-
> > episode-13/)
>
> What if you list all host names in single ServerAlias directive and
> not multiple.
>
>  http://httpd.apache.org/docs/2.2/mod/core.html#serveralias
>
> > 2) In addition, the admin backend doesn't work on the production
> > server (I get a 404 error) regardless of whether or not I pre-pend the
> > "www". Apache error logs stated that the sqlite database backend did
> > not have write permissions, but the 404 errors persisted even after I
> > added the permissions (chmod 755).
>
> You have:
>
>   ADMIN_MEDIA_PREFIX = '/media/'
>
> yet that doesn't appear to be where media files are being served from.
>
> Your configuration is a bit confusing with nginx in front and both
> nginx and Apache both attempting to serve static files. Suggest you
> get Apache working with static files first and ignore nginx until you
> have that working and understand how things are affected by Django
> settings for media.
>
> Graham
>
> > Any suggestions would be greatly appreciated!!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



configuring production server for static media

2008-11-19 Thread Serdar T.

Hello folks,
Can anyone out there offer advice on glitches in my production
environment, as well as explain the relevant settings.py in plain
English for a newbie?

I've been pulling my hair out for weeks trying to get an nginx reverse
proxy to serve static media while apache mod_wsgi serves up dynamic
django content. The dynamic content is being served, and I can access
the index of media files in a browser by visiting the MEDIA_URL.

But for some reason, media does not get served when I access the admin
backend. I get the login screen without any of the stylesheets,
javascript, etc. (and a 500 error when I try to login).

I haven't had any luck despite countless tweaks to MEDIA_ROOT,
MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
to nginx and apache config files).

At the bottom of the post are my various config files. I was hoping
someone could point out whatever dumb mistake I'm making.
Additionally, if someone could explain the concepts behind the
settings.py file and how they relate back to the server config files
-- that would be enormously helpful (the django docs and countless
threads I've read on the subject don't connect the dots clearly enough
-- at least for me).

 I'm hoping a basic explanation might let me penetrate the problem
conceptually, so I'm not just futzing around with tweaks with no idea
what's really happening.

Can someone teach a man to fish?



settings.py
MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
MEDIA_URL = 'http://media.mysite.org/'
ADMIN_MEDIA_PREFIX = '/media/'


**/etc/nginx/nginx.conf*
user www-data;
worker_processes  3;

error_log  /var/log/nginx/error.log;
pid/var/run/nginx.pid;

events {
worker_connections  1024;
}

http {
include   /etc/nginx/mime.types;
default_type  application/octet-stream;

access_log  /var/log/nginx/access.log;

sendfileon;
#tcp_nopush on;

#keepalive_timeout  0;
keepalive_timeout  10;
tcp_nodelayon;

gzip  on;

upstream webcluster {
server 127.0.0.1:8080;
}

include /etc/nginx/sites-enabled/*;

}


*/etc/nginx/sites-available/mysite.org*
server {
listen 80;
server_name media.mysite.org;
access_log /var/log/nginx/mysite.media.access.log;
location / {
autoindex on;
index index.html;
root /home/user/public_html/mysite/public/media;

}
}

server {
listen 80;
server_name mysite.org www.mysite.org;
access_log /var/log/nginx/mysite.django.access.log;
if ($host !~* "^mysite\.org") {
rewrite ^(.*)$ http://mysite.org$1 permanent;
break;
}
location / {
proxy_pass http://webcluster;
include /etc/nginx/proxy.conf;
}
}


*/etc/apache2/sites-available/mysite.org**

ServerAdmin [EMAIL PROTECTED]
ServerName www.mysite.org
ServerAlias mysite.org
WSGIScriptAlias / /home/user/public_html/mysite/test_app/
mysite.wsgi


Order deny,allow
Allow from all


LogLevel debug
ErrorLog /var/log/apache2/mysite/error.log
CustomLog /var/log/apache2/mysite/access.log combined






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: configuring production server for static media

2008-11-19 Thread Serdar T.

hmm...I modified the root as you suggested but still the same results:
I get the admin page minus any stylesheets, etc.

I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?

 It seems that the setting tacks "/media" to the end of root path as a
way of defining where the server should search for media.

But if the "media" directory is being appended to the end of the path,
why is it called a prefix?



On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> If:
>
>   ADMIN_MEDIA_PREFIX = '/media/'
>
> means that static media URLs will all be prefixed with that, then
> wouldn't:
>
>   root /home/user/public_html/mysite/public/media;
>
> need to be:
>
>   root /home/user/public_html/mysite/public;
>
> This is because you have location '/' on nginx mapped to this
> directory.
>
> Graham
>
> On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > Hello folks,
> > Can anyone out there offer advice on glitches in my production
> > environment, as well as explain the relevant settings.py in plain
> > English for a newbie?
>
> > I've been pulling my hair out for weeks trying to get an nginx reverse
> > proxy to serve static media while apache mod_wsgi serves up dynamic
> > django content. The dynamic content is being served, and I can access
> > the index of media files in a browser by visiting the MEDIA_URL.
>
> > But for some reason, media does not get served when I access the admin
> > backend. I get the login screen without any of the stylesheets,
> > javascript, etc. (and a 500 error when I try to login).
>
> > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > to nginx and apache config files).
>
> > At the bottom of the post are my various config files. I was hoping
> > someone could point out whatever dumb mistake I'm making.
> > Additionally, if someone could explain the concepts behind the
> > settings.py file and how they relate back to the server config files
> > -- that would be enormously helpful (the django docs and countless
> > threads I've read on the subject don't connect the dots clearly enough
> > -- at least for me).
>
> >  I'm hoping a basic explanation might let me penetrate the problem
> > conceptually, so I'm not just futzing around with tweaks with no idea
> > what's really happening.
>
> > Can someone teach a man to fish?
>
> > settings.py
> > MEDIA_ROOT = '/home/user/public_html/mysite/public/media/'
> > MEDIA_URL = 'http://media.mysite.org/'
> > ADMIN_MEDIA_PREFIX = '/media/'
>
> > **/etc/nginx/nginx.conf*
> > user www-data;
> > worker_processes  3;
>
> > error_log  /var/log/nginx/error.log;
> > pid/var/run/nginx.pid;
>
> > events {
> > worker_connections  1024;
>
> > }
>
> > http {
> > include   /etc/nginx/mime.types;
> > default_type  application/octet-stream;
>
> > access_log  /var/log/nginx/access.log;
>
> > sendfileon;
> > #tcp_nopush on;
>
> > #keepalive_timeout  0;
> > keepalive_timeout  10;
> > tcp_nodelayon;
>
> > gzip  on;
>
> > upstream webcluster {
> > server 127.0.0.1:8080;
> > }
>
> > include /etc/nginx/sites-enabled/*;
>
> > }
>
> > */etc/nginx/sites-available/mysite.org*
> > server {
> > listen 80;
> > server_name media.mysite.org;
> > access_log /var/log/nginx/mysite.media.access.log;
> > location / {
> > autoindex on;
> > index index.html;
> > root /home/user/public_html/mysite/public/media;
>
> > }
>
> > }
>
> > server {
> > listen 80;
> > server_name mysite.orgwww.mysite.org;
> > access_log /var/log/nginx/mysite.django.access.log;
> > if ($host !~* "^mysite\.org") {
> > rewrite ^(.*)$http://mysite.org$1permanent;
> > break;
> > }
> > location / {
> > proxy_passhttp://webcluster;
> > include /etc/nginx/proxy.conf;
> > }
>
> > }
>
> > */etc/apache2/sites-available/mysite.org**
> > 
> 

Re: configuring production server for static media

2008-11-19 Thread Serdar T.



On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > hmm...I modified the root as you suggested but still the same results:
> > I get the admin page minus any stylesheets, etc.
>
> > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> >  It seems that the setting tacks "/media" to the end of root path as a
> > way of defining where the server should search for media.
>
> > But if the "media" directory is being appended to the end of the path,
> > why is it called a prefix?
>
> Please provide a snippet of the HTML pages being served which show the
> actual URLs which are generated in the response.



2http://www.w3.org/1999/xhtml"; lang="en-us" xml:lang="en-
us" >
3
4Log in | Django site admin
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 
21 
22 
23
24Django administration
25
26 
27
28
29 
30 
<<>>


> Also indicate whether you have validated that you can access the
> static media files from nginx media site and exactly what the URLs you
> have managed to successfully access them using are.

Yup, when I turn indexing on in nginx configs, I'm able to view the
media files at the following URL subdomain:

http://media.mysite.org/

gives acess the following directory heirarchy:

../
media/
  ../
  css/   10-
Nov-2008 14:05   -
  img/   10-
Nov-2008 14:05   -
  js/
 <>

>
> A directory list of what is actually in:
>
>   /home/user/public_html/mysite/public

the "/media" directory is the only thing in this directory.
It is a symlink to django's admin media file, located in the following
directory:

/home/user/python/django-trunk/django/contrib/admin/media

>   /home/user/public_html/mysite/public/media
media, as stated above, is a symlink to django's admin/media directory


> would be useful as well.
>
> Graham
>
> > On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > wrote:
>
> > > If:
>
> > >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > > means that static media URLs will all be prefixed with that, then
> > > wouldn't:
>
> > >   root /home/user/public_html/mysite/public/media;
>
> > > need to be:
>
> > >   root /home/user/public_html/mysite/public;
>
> > > This is because you have location '/' on nginx mapped to this
> > > directory.
>
> > > Graham
>
> > > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > Hello folks,
> > > > Can anyone out there offer advice on glitches in my production
> > > > environment, as well as explain the relevant settings.py in plain
> > > > English for a newbie?
>
> > > > I've been pulling my hair out for weeks trying to get an nginx reverse
> > > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > > django content. The dynamic content is being served, and I can access
> > > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > > But for some reason, media does not get served when I access the admin
> > > > backend. I get the login screen without any of the stylesheets,
> > > > javascript, etc. (and a 500 error when I try to login).
>
> > > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding changes
> > > > to nginx and apache config files).
>
> > > > At the bottom of the post are my various config files. I was hoping
> > > > someone could point out whatever dumb mistake I'm making.
> > > > Additionally, if someone could explain the concepts behind the
> > > > settings.py file and how they relate back to the server config files
> > > > -- that would be enormously helpful (the django docs and countless
> > > > threads I've read on the subject don't connect the dots clearly enough
> > > > -- at least for me).
>
> > > >  I'm hoping a basic explanation might let me penetrate the problem
> > > > conceptually, so I'm not just futzing around with tweaks with no idea
> > > > what's really happening.
>
> > > > Can someone teach a man to fish?
>
> > > > settings.py
> >

Re: configuring production server for static media

2008-11-19 Thread Serdar T.

I think my prior response missed the mark in terms of sample html and
url.

To be precise:

http://mysite.org/admin/

yields the below html:


http://www.w3.org/1999/xhtml"; lang="en-us" xml:lang="en-
us" >

Log in | Django site admin

















<<<>>>



On Nov 19, 10:58 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
> On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:
>
> > On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > hmm...I modified the root as you suggested but still the same results:
> > > I get the admin page minus any stylesheets, etc.
>
> > > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> > >  It seems that the setting tacks "/media" to the end of root path as a
> > > way of defining where the server should search for media.
>
> > > But if the "media" directory is being appended to the end of the path,
> > > why is it called a prefix?
>
> > Please provide a snippet of the HTML pages being served which show the
> > actual URLs which are generated in the response.
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> 2http://www.w3.org/1999/xhtml"; lang="en-us" xml:lang="en-
> us" >
> 3
> 4Log in | Django site admin
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20 
> 21 
> 22 
> 23
> 24Django administration
> 25
> 26 
> 27
> 28
> 29 
> 30 
> <<>>
>
> > Also indicate whether you have validated that you can access the
> > static media files from nginx media site and exactly what the URLs you
> > have managed to successfully access them using are.
>
> Yup, when I turn indexing on in nginx configs, I'm able to view the
> media files at the following URL subdomain:
>
> http://media.mysite.org/
>
> gives acess the following directory heirarchy:
>
> ../
> media/
>   ../
>   css/   10-
> Nov-2008 14:05   -
>   img/   10-
> Nov-2008 14:05   -
>   js/
>  <>
>
>
>
> > A directory list of what is actually in:
>
> >   /home/user/public_html/mysite/public
>
> the "/media" directory is the only thing in this directory.
> It is a symlink to django's admin media file, located in the following
> directory:
>
> /home/user/python/django-trunk/django/contrib/admin/media
>
> >   /home/user/public_html/mysite/public/media
>
> media, as stated above, is a symlink to django's admin/media directory
>
> > would be useful as well.
>
> > Graham
>
> > > On Nov 19, 7:43 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > If:
>
> > > >   ADMIN_MEDIA_PREFIX = '/media/'
>
> > > > means that static media URLs will all be prefixed with that, then
> > > > wouldn't:
>
> > > >   root /home/user/public_html/mysite/public/media;
>
> > > > need to be:
>
> > > >   root /home/user/public_html/mysite/public;
>
> > > > This is because you have location '/' on nginx mapped to this
> > > > directory.
>
> > > > Graham
>
> > > > On Nov 20, 10:45 am, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > > Hello folks,
> > > > > Can anyone out there offer advice on glitches in my production
> > > > > environment, as well as explain the relevant settings.py in plain
> > > > > English for a newbie?
>
> > > > > I've been pulling my hair out for weeks trying to get an nginx reverse
> > > > > proxy to serve static media while apache mod_wsgi serves up dynamic
> > > > > django content. The dynamic content is being served, and I can access
> > > > > the index of media files in a browser by visiting the MEDIA_URL.
>
> > > > > But for some reason, media does not get served when I access the admin
> > > > > backend. I get the login screen without any of the stylesheets,
> > > > > javascript, etc. (and a 500 error when I try to login).
>
> > > > > I haven't had any luck despite countless tweaks to MEDIA_ROOT,
> > > > > MEDIA_URL, and ADMIN_MEDIA_PREFIX  (along with corresponding chang

Re: configuring production server for static media

2008-11-20 Thread Serdar T.

ok. so that fix workedkind of.

I now get the properly formatted admin login page when I visit
http://mysite.org/admin/

But when I log in,  the following 500 Internal Server Error appears:
"I'm sorry, that page is currently unavailable due to a server
misconfiguration."

That is actually a custom error page I placed in my django project's
template directory. When I clear the cache, cookies and authenticated
sessions, I can hit refresh on the admin URL and once again call up
the admin login page (complete with the stylesheets etc.). But then I
get an error stating that cookies appear to not be enabled. And when I
click login, I'm right back where I started: 500 error.

Any ideas on how to proceed?


On Nov 20, 12:06 am, Graham Dumpleton <[EMAIL PROTECTED]>
wrote:
> Try:
>
>   ADMIN_MEDIA_PREFIX = 'http://media.mysite.org/media/'
>
> Web site example always show just a path and not a site name, but
> source code shows it can be  full URL with site name.
>
> # URL prefix for admin media -- CSS, JavaScript and images. Make sure
> to use a
> # trailing slash.
> # Examples: "http://foo.com/media/";, "/media/".
> ADMIN_MEDIA_PREFIX = '/media/'
>
> I guess I'd always assumed that this prefix was added on top of
> MEDIA_URL, but apparently not. Thus if on different site, looks like
> you need to state host as well.
>
> Graham
>
> On Nov 20, 3:06 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > I think my prior response missed the mark in terms of sample html and
> > url.
>
> > To be precise:
>
> >http://mysite.org/admin/
>
> > yields the below html:
>
> >  > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> > http://www.w3.org/1999/xhtml"; lang="en-us" xml:lang="en-
> > us" >
> > 
> > Log in | Django site admin
> > 
> > 
>
> > 
> > 
>
> > 
>
> > 
>
> > 
>
> > 
> > 
> > 
>
> > <<<>>>
>
> > On Nov 19, 10:58 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > On Nov 19, 10:32 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > On Nov 20, 2:10 pm, "Serdar T." <[EMAIL PROTECTED]> wrote:
>
> > > > > hmm...I modified the root as you suggested but still the same results:
> > > > > I get the admin page minus any stylesheets, etc.
>
> > > > > I'm confused though: what exactly is the ADMIN_MEDIA_PREFIX prefixing?
>
> > > > >  It seems that the setting tacks "/media" to the end of root path as a
> > > > > way of defining where the server should search for media.
>
> > > > > But if the "media" directory is being appended to the end of the path,
> > > > > why is it called a prefix?
>
> > > > Please provide a snippet of the HTML pages being served which show the
> > > > actual URLs which are generated in the response.
>
> > >  > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> > > 2http://www.w3.org/1999/xhtml"; lang="en-us" xml:lang="en-
> > > us" >
> > > 3
> > > 4Log in | Django site admin
> > > 5
> > > 6
> > > 7
> > > 8
> > > 9
> > > 10
> > > 11
> > > 12
> > > 13
> > > 14
> > > 15
> > > 16
> > > 17
> > > 18
> > > 19
> > > 20 
> > > 21 
> > > 22 
> > > 23
> > > 24Django administration
> > > 25
> > > 26 
> > > 27
> > > 28
> > > 29 
> > > 30 
> > > <<>>
>
> > > > Also indicate whether you have validated that you can access the
> > > > static media files from nginx media site and exactly what the URLs you
> > > > have managed to successfully access them using are.
>
> > > Yup, when I turn indexing on in nginx configs, I'm able to view the
> > > media files at the following URL subdomain:
>
> > >http://media.mysite.org/
>
> > > gives acess the following directory heirarchy:
>
> > > ../
> > > media/
> > >   ../
> > >   css/   10-
> > > Nov-2008 14:05   -
> > >   img/   10-
> > > Nov-2008 14:05       -
> > >   

Re: configuring production server for static media

2008-11-21 Thread Serdar T.

For posterity, I should point out that Graham's suggestion did indeed
work and the final set of problems stemmed from my django app code. I
had copied over some old code from my development environment to the
production server, but the dev server was running an older version of
django so the code required some updates.

A thousand thanks to Graham for helping iron out the configuration
kinks and to Karen for reminding me to go back to basics and use
Debug. (and apologies for the earlier top posts)

Cheers!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



serializing vs. building a JSON response -- is there a best practice?

2009-02-06 Thread Serdar T.

Hey everyone,
I'm' working on a basic chained select menu that lets you drill down
from county to town to restaurant. The men is populated dynamically
using ajax calls from browser to Django on the server side.

It's working as intended, but I'm wondering if there is a "best
practice" or convention  for returning JSON from Django. My initial
Django view built up a JSON response by looping over the results of a
database query. A friend who uses a different language/framework then
advised that I should avoid  building my own JSON responses and
instead rely (whenever possible) on JSON libraries or serializers. He
said that provides better assurance you'll be sending properly
formatted JSON back to the browser.

Snippets from both implementations are below, and each worked for my
simple use-case.
So I'm wondering -- other than the issue raised above, is there a
preferred method for generating JSON?
Perhaps based on concerns about speed, efficiency or some other
factor? Any advice is appreciated.

JSON response built with
"manually"-

def ajax_parser(request):
<>
county = request.GET['param']
towns = Town.objects.filter(county=county)

townList = [ ]

for town in towns:
options = { }
options['name'] = "%s" % (town)
options['value'] = town.id
townList.append(options)
<>

-JSON response using
serializer---

def ajax_parser(request):
>
if xhr:
try:
search = request.GET['search']
if search == 'county':
#client sends county integer for Town lookup
county = request.GET['param']
#generate JSON response for client - primary key
becomes Option value and municipality becomes Option text/name
data = serializers.serialize("json",
Town.objects.filter(county=county), fields=('pk','municipality') )

elif search == 'muni':
#client sends muni primary key for Restaurant lookup
muni = request.GET['param']
data = serializers.serialize("json",
Restaurant.objects.filter(municipality=muni), fields=('pk','name') )

return HttpResponse(data, mimetype='application/json')
<>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



version control convention?

2009-02-10 Thread Serdar T.

Is it better to create repositories at a site-, project- or app-level?

In other words, if I implement the conventional[1] directory structure
below, is it better to place the entire site (example.com) under a
single git repository, or would it be wiser to create separate git
repos for each custom app?

Any suggestions on the best course of action (Perhaps something to add
to the conventions list)?

example.com/
   settings.py
   urls.py
   local_apps/
   custom apps written for this project (Preferably Reusable;
Probably on your PYTHONPATH)
   external_apps/
External reusable apps you are using on this project
Note: These apps can also live anywhere on your PYTHONPATH
   projects/
   dev_example/
   production_example/
   django96_example/
   manage.py, settings, urls, etc
docs/
   This will hold the documentation for your project
   static/
   -In production this will be the root of your MEDIA_URL
   css/
   js/
   images/
   tests/
   - Project level tests (Each app should also have tests)
   uploads/
   - content imgs, etc
   templates/
   - This area is used to override templates from your reusable
apps
   flatpages/
   comments/
   example/
   app1/
   app2/

[1] http://ericholscher.com/projects/reusable-app-docs/projects/overview.html
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django nube

2009-02-26 Thread Serdar T.



> j...@john-laptop:~/Django/mysite$ ls -l

Try using the full path to the file rather than the ~ shortcut:

/home/username/Django/mysite/mysite_data.db
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



loaddata spewing to standard output but not actually loading

2009-03-06 Thread Serdar T.

Hey everyone,

While trying to load a json fixture, the contents are spitting out to
my bash shell but nothing is loading into the postgres database
backend.

>From inside my project directory, I'm executing the documented
command:

./manage.py loaddata data2.json

In addition to the contents, the only message I get from Django is:

"Installing json fixture 'data2' from absolute path."

But again, nothing is winding up in the database.

I should mention that this fixture was originally dumped from another
Django project. I renamed the Django app inside the fixture so that it
would match my new project (which otherwise has an identical schema).
While the updated fixture chokes, I'm able to successfully load a
fixture that was produced by after loading a portion of my data
manually thgrough the postgres backend.

Below are two slices from the fixture that works (budtype.json) and
the one that chokes (data2.json). Would love to hear if anyone has any
suggestions.

budtype.json#
#This fixture loads properly
1 [
2 {
3 "pk": 1,
4 "model": "reportcard.budtype",
5 "fields": {
6 "type": "K-6"
7 }
8 },
   <>

data2.json
#This fixture does not load
1 [
2 {
3 "pk": 1,
4 "model": "reportcard.budtype",
5 "fields": {
6 "type": "K-6"
7 }
8 },
<>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: loaddata spewing to standard output but not actually loading

2009-03-08 Thread Serdar T.

Hi Russell,
Thanks for the response. I'll admit, since I posted, I waved my hand
at the problem and imported all of my data through postgres. But I
think my problem might be related to what you describe below:

> > "Installing json fixture 'data2' from absolute path."
>
> This gives the first hint as to what might be going on - where is the
> data2 fixture located? It's possible that the fixture that you think
> is being loaded isn't actually the one that is being loaded. The
> 'absolute path' message suggests that there is a data2 fixture in your
> project directory (i.e., the directory where manage.py is located). If
> budtype.json is actually .../app/fixtures/budtype.json, the actual
> error here could be that you have a stray data2 fixture that is being
> picked up by Django's fixture discovery procedure.

The data2.json and budtype.json fixtures were both located in my
project-level directory.  But I did have a data2.json file in the
original project directory from which I copied the fixture. I've since
deleted that project (and app), but it was on my PYTHONPATH at the
time I was trying to load the fixture in the new project.

So I'm curious - Does loaddata check all directories on the PYTHONPATH
for the named fixture? Or does it only check for fixtures inside the
project directory where the loaddata command was executed?

If it checks everything on the PYTHONPATH, I suspect I might have been
running into the stray fixture problem you mentioned.

> Sometimes, this process will reveal the blindingly obvious problem
> between the keyboard and chair :-)

This tends to be the root of nearly all my glitches!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



config dev server for static media

2009-03-09 Thread Serdar T.

Hey everyone,
Yes, this is yet another plea for help on configuring the dev server
for static media.

 [insert disclaimer here about reading (and re-reading) docs,
countless tutorials, etc.]

I believe I have everything set up correctly, yet I can't seem to get
Django to serve static media on my dev server. The admin site works
flawlessly, but none of my own css will serve properly. I can reach my
static media files at:

http://localhost:8000/static/css/base_test.css/

On my django page,  I use the following link:



But no dice. None of the styling rules are applied.

Below I've included my directory structure and relevant settings. Can
someone point out the stupid mistake that's driving me to the border
of insanity??

/project
settings.py
urls.py
/app1
/static
/css
base_test.css
/templates
base_test.html
/app1
app1_section.html (extends base)

-settings.py-
MEDIA_ROOT = '/home/user/web/project/static'
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX =  '/static/admin/'

urls.py-
import os
from django.conf import settings
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: config dev server for static media

2009-03-09 Thread Serdar T.

So I'm continuing to look for the source of bugs on this front, and
wanted to add a note on a strange PYTHONPATH issue that I've
encountered.

When I fire up ipython from my project directory (using ./manage.py
shell) , the PYTHONPATH includes the following paths for my project:

 '/home/user/web/project/',
 '/home/user/web/project/..',
 '/home/user/web/project/../project',

That seems very strange to me, since I only intended to add the base
project directory to the list of PYTHONPATHS. To do so, I added the
following to my project directory's __init__.py :

from os.path import dirname
from sys import path

path.append(dirname(__file__))

Even more strange, when I comment out that code, the pythonpath now
includes just the root project directory:
 '/home/user/web/project/',

However, when I fire up the normal python interpreter, the project is
not included on the pythonpath.

All of this, of course, has not resolved the issue, but leads me to
wonder if Django is:
a) automagically appending my project directory to the pythonpath when
I run the ./manage.py shell
b) somehow stomping on my pythonpath configurations when I run the
devserver

Anyone have any advice?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: config dev server for static media

2009-03-09 Thread Serdar T.

Ok. So are the additional dotted paths being added by the shell in
order to search the child directories of my project? It occurred to me
after I posted that the second of the three paths ( '/home/user/web/
project/..', ) might map to my static/ or templates/ directories, for
instance.

The third path ( '/home/user/web/project/../project', ) remains a
mystery...
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: config dev server for static media

2009-03-09 Thread Serdar T.

OK. So for posterity's sake, I wanted to note that I solved this
problem, and it was completely my own embarrassingly stupid oversight
(is there a Jargon acronym for telling yourself to read your own
source more closely?).

The problem was not the project layout or Django code, but the link in
the html page to the stylesheet.

This link
  
...had an incorrect attribute:
 rel="stylesheet/css" should be just rel="stylesheet"

The correct link:


I must have looked at that link dozens of times until I noticed it.
Apologies for cluttering the list with my brainlapse.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Datefield auto_now_add not working with sqlite3?

2009-10-05 Thread Serdar T.

Hi everyone,
I'm having a problem with the "auto_now_add" option for DateField.

I was under the impression that when you set this option, a datestamp
is set automatically for you. But when I try inserting records into my
database without supplying a date for this field, I get a NULL value
error:

"calendar.date_added_to_db may not be NULL"

Below is the relevant portion of my model definition:

class Event(models.Model):
date = models.DateField()
title = models.TextField()
url = models.URLField()
date_added_to_db = models.DateField(auto_now_add=True)

And the results of python manage.py sqlall:

BEGIN;
CREATE TABLE "calendar" (
"id" integer NOT NULL PRIMARY KEY,
"date" date NOT NULL,
"title" text NOT NULL,
"url" varchar(200) NOT NULL,
"date_added_to_db" date NOT NULL
)
;
COMMIT;

I'm confused as to why Django's ORM would translate the
"date_added_to_db" field as the above SQL. It would seem more
appropriate for the "date_added_to_db" field to be translated as the
following SQL:

 "DATETIME NOT NULL DEFAULT CURRENT_DATE"

With the above field definition, the datestamp is set automatically
for me when a record is created (which is the behavior I'm after).

Am I misconfiguring something, or is this an issue perhaps with the
implementation of the auto_now_add option for sqlite3? Or perhaps it's
convention to pass in the date/timestamp (though in that case, I don't
see the point of having the "auto_now_add" option)?

 If it helps, I'm using sqlite3, Django 1.1 and Python 2.6.2.

Any advice is appreciated.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---