Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: users

Django and Custom environment variables

 

 

Cherokee users RSS feed   Index | Next | Previous | View Threaded


mariocesar.c50 at gmail

Aug 11, 2009, 8:15 PM

Post #1 of 10 (524 views)
Permalink
Django and Custom environment variables

Hello all,

I was trying to deploy a Django application for managing subdomains as
specific apps, something like devianart.com for example. that
username.domain.com trows the user dashboard instead the homepage of the
website.

So, I came with a solution, to chose the urls.py of the project making a
difference if the user come from the main domain or a subdomain, if on
the request I get the subdomain I load just an specific urls.py.

In my 'plans' I need to to create a vhost for the main site, that
catches the domain.com and www.domain.com, and another vhost that caches
everything else *.domain.com, both vhost would have the same Information
Source, to get the load of the urls.py be different I want to set
something like a *custom* setting for each vhost, creating a Custom
Environment variable in the SCGI handler.

In my understanding creating some X_SETTING with the value 1, for
example. I could get the value on the django application doing

import os
xsetting = os.environ['X_SETTING']
if xsetting == 0:
#load the main domain urls.py
elif xsetting == 1
#load the some user app urls.py

This, as for me looks logical, always raise an non existing key
exception, Am I understanding well the use of the Custom Environment
Variables? This works as I am thinking? Is obvious that no :)

I would appreciate any hint about the usage of the Custom Environ
Variables.

--
Mario César Señoranis Ayala

Twitter: http://twitter.com/mariocesar_bo
Arte: http://mariocesar.deviantart.com
Blog Software Libre: http://softwarelibre.org.bo/mariocesar
Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
Attachments: signature.asc (0.19 KB)


pablosaro at gmail

Aug 11, 2009, 8:53 PM

Post #2 of 10 (504 views)
Permalink
Re: Django and Custom environment variables [In reply to]

Ooops! I forgot the list. Sorry...
Read below.

On Wed, Aug 12, 2009 at 12:52 AM, Pablo Hernan Saro <pablosaro [at] gmail>wrote:

> Hi Mario,
>
> As far as I know, you can do something like this in apache (in the vhost
> configuration):
> ServerAlias *.yourdomain.com
>
> Well, this is cherokee, I know... Don't punch me! =P
> If cherokee is able to do something like this, then it is so easy to handle
> subdomains in Django.
> If you request hotpotato.example.com, Django provides
> request.META['HTTP_HOST'] with that information. So you can play a little
> bit to accomplish what you need by simply splitting it and getting the
> subdomain (hotpotato). Then you can call a view named as the requested
> subdomain (just an example).
>
> So, my question would be: is cherokee able to handle wildcards in vhosts
> definition?
>
> Hope it helps.
> Cheers
>
> Pablo
>
> 2009/8/12 Mario César Señoranis <mariocesar.c50 [at] gmail>
>
>> Hello all,
>>
>> I was trying to deploy a Django application for managing subdomains as
>> specific apps, something like devianart.com for example. that
>> username.domain.com trows the user dashboard instead the homepage of the
>> website.
>>
>> So, I came with a solution, to chose the urls.py of the project making a
>> difference if the user come from the main domain or a subdomain, if on
>> the request I get the subdomain I load just an specific urls.py.
>>
>> In my 'plans' I need to to create a vhost for the main site, that
>> catches the domain.com and www.domain.com, and another vhost that caches
>> everything else *.domain.com, both vhost would have the same Information
>> Source, to get the load of the urls.py be different I want to set
>> something like a *custom* setting for each vhost, creating a Custom
>> Environment variable in the SCGI handler.
>>
>> In my understanding creating some X_SETTING with the value 1, for
>> example. I could get the value on the django application doing
>>
>> import os
>> xsetting = os.environ['X_SETTING']
>> if xsetting == 0:
>> #load the main domain urls.py
>> elif xsetting == 1
>> #load the some user app urls.py
>>
>> This, as for me looks logical, always raise an non existing key
>> exception, Am I understanding well the use of the Custom Environment
>> Variables? This works as I am thinking? Is obvious that no :)
>>
>> I would appreciate any hint about the usage of the Custom Environ
>> Variables.
>>
>> --
>> Mario César Señoranis Ayala
>>
>> Twitter: http://twitter.com/mariocesar_bo
>> Arte: http://mariocesar.deviantart.com
>> Blog Software Libre: http://softwarelibre.org.bo/mariocesar
>> Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
>>
>> _______________________________________________
>> Cherokee mailing list
>> Cherokee [at] lists
>> http://lists.octality.com/listinfo/cherokee
>>
>>
>


pablosaro at gmail

Aug 11, 2009, 8:58 PM

Post #3 of 10 (502 views)
Permalink
Re: Django and Custom environment variables [In reply to]

VOILA!
Of course wildcards work on cherokee.
So Mario, what I suggested should work like a charm.
Cheers

Pablo

On Wed, Aug 12, 2009 at 12:53 AM, Pablo Hernan Saro <pablosaro [at] gmail>wrote:

> Ooops! I forgot the list. Sorry...
> Read below.
>
>
> On Wed, Aug 12, 2009 at 12:52 AM, Pablo Hernan Saro <pablosaro [at] gmail>wrote:
>
>> Hi Mario,
>>
>> As far as I know, you can do something like this in apache (in the vhost
>> configuration):
>> ServerAlias *.yourdomain.com
>>
>> Well, this is cherokee, I know... Don't punch me! =P
>> If cherokee is able to do something like this, then it is so easy to
>> handle subdomains in Django.
>> If you request hotpotato.example.com, Django provides
>> request.META['HTTP_HOST'] with that information. So you can play a little
>> bit to accomplish what you need by simply splitting it and getting the
>> subdomain (hotpotato). Then you can call a view named as the requested
>> subdomain (just an example).
>>
>> So, my question would be: is cherokee able to handle wildcards in vhosts
>> definition?
>>
>> Hope it helps.
>> Cheers
>>
>> Pablo
>>
>> 2009/8/12 Mario César Señoranis <mariocesar.c50 [at] gmail>
>>
>>> Hello all,
>>>
>>> I was trying to deploy a Django application for managing subdomains as
>>> specific apps, something like devianart.com for example. that
>>> username.domain.com trows the user dashboard instead the homepage of the
>>> website.
>>>
>>> So, I came with a solution, to chose the urls.py of the project making a
>>> difference if the user come from the main domain or a subdomain, if on
>>> the request I get the subdomain I load just an specific urls.py.
>>>
>>> In my 'plans' I need to to create a vhost for the main site, that
>>> catches the domain.com and www.domain.com, and another vhost that caches
>>> everything else *.domain.com, both vhost would have the same Information
>>> Source, to get the load of the urls.py be different I want to set
>>> something like a *custom* setting for each vhost, creating a Custom
>>> Environment variable in the SCGI handler.
>>>
>>> In my understanding creating some X_SETTING with the value 1, for
>>> example. I could get the value on the django application doing
>>>
>>> import os
>>> xsetting = os.environ['X_SETTING']
>>> if xsetting == 0:
>>> #load the main domain urls.py
>>> elif xsetting == 1
>>> #load the some user app urls.py
>>>
>>> This, as for me looks logical, always raise an non existing key
>>> exception, Am I understanding well the use of the Custom Environment
>>> Variables? This works as I am thinking? Is obvious that no :)
>>>
>>> I would appreciate any hint about the usage of the Custom Environ
>>> Variables.
>>>
>>> --
>>> Mario César Señoranis Ayala
>>>
>>> Twitter: http://twitter.com/mariocesar_bo
>>> Arte: http://mariocesar.deviantart.com
>>> Blog Software Libre: http://softwarelibre.org.bo/mariocesar
>>> Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
>>>
>>> _______________________________________________
>>> Cherokee mailing list
>>> Cherokee [at] lists
>>> http://lists.octality.com/listinfo/cherokee
>>>
>>>
>>
>


mariocesar.c50 at gmail

Aug 11, 2009, 9:08 PM

Post #4 of 10 (494 views)
Permalink
Re: Django and Custom environment variables [In reply to]

El mié, 12-08-2009 a las 00:58 -0300, Pablo Hernan Saro escribió:
> VOILA!
> Of course wildcards work on cherokee.
> So Mario, what I suggested should work like a charm.
> Cheers
>
> Pablo
>
> On Wed, Aug 12, 2009 at 12:53 AM, Pablo Hernan Saro
> <pablosaro [at] gmail> wrote:
> Ooops! I forgot the list. Sorry...
> Read below.
>
>
>
> On Wed, Aug 12, 2009 at 12:52 AM, Pablo Hernan Saro
> <pablosaro [at] gmail> wrote:
> Hi Mario,
>
> As far as I know, you can do something like this in
> apache (in the vhost configuration):
> ServerAlias *.yourdomain.com
>
> Well, this is cherokee, I know... Don't punch me! =P
> If cherokee is able to do something like this, then it
> is so easy to handle subdomains in Django.
> If you request hotpotato.example.com, Django provides
> request.META['HTTP_HOST'] with that information. So
> you can play a little bit to accomplish what you need
> by simply splitting it and getting the subdomain
> (hotpotato). Then you can call a view named as the
> requested subdomain (just an example).
>
> So, my question would be: is cherokee able to handle
> wildcards in vhosts definition?
>
> Hope it helps.
> Cheers
>

yes, indeed I am not using wildcards, as the mighty cherokee can do, I
am using regular expresion, to get sure the domains wiki.domain.com,
help.domain.com, mail.domain.com not get use on the vhost.

The problem isn't if *I can use subdomains in cherokee?*

About the HTTP_HOST, yes it was my first idea, but it need to get a
calculation on each one of my views, that is not desireble for me, why
calculate in request of a page if I am on subdomain.

As I was hoping, If I can setup to load specific urls, just when the
user hit the subdomain would be great.
Attachments: signature.asc (0.19 KB)


listas at enelserver

Aug 12, 2009, 4:33 AM

Post #5 of 10 (497 views)
Permalink
Re: Django and Custom environment variables [In reply to]

> Hello all,
>
> I was trying to deploy a Django application for managing subdomains as
> specific apps, something like devianart.com for example. that
> username.domain.com trows the user dashboard instead the homepage of the
> website.
>
> So, I came with a solution, to chose the urls.py of the project making a
> difference if the user come from the main domain or a subdomain, if on
> the request I get the subdomain I load just an specific urls.py.
>
> In my 'plans' I need to to create a vhost for the main site, that
> catches the domain.com and www.domain.com, and another vhost that caches
> everything else *.domain.com, both vhost would have the same Information
> Source, to get the load of the urls.py be different I want to set
> something like a *custom* setting for each vhost, creating a Custom
> Environment variable in the SCGI handler.
>
> In my understanding creating some X_SETTING with the value 1, for
> example. I could get the value on the django application doing
>
> import os
> xsetting = os.environ['X_SETTING']
> if xsetting == 0:
> #load the main domain urls.py
> elif xsetting == 1
> #load the some user app urls.py
>
> This, as for me looks logical, always raise an non existing key
> exception, Am I understanding well the use of the Custom Environment
> Variables? This works as I am thinking? Is obvious that no :)
>
> I would appreciate any hint about the usage of the Custom Environ
> Variables.
>
> --
> Mario César Señoranis Ayala
>
> Twitter: http://twitter.com/mariocesar_bo
> Arte: http://mariocesar.deviantart.com
> Blog Software Libre: http://softwarelibre.org.bo/mariocesar
> Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
>
> _______________________________________________
> Cherokee mailing list
> Cherokee [at] lists
> http://lists.octality.com/listinfo/cherokee
>
>


Django sites can help take a look at:

http://docs.djangoproject.com/en/dev/ref/contrib/sites/?from=olddocs#django.contrib.sites.django.contrib.sites.models.Site



saludos


Leonel


_______________________________________________
Cherokee mailing list
Cherokee [at] lists
http://lists.octality.com/listinfo/cherokee


mariocesar.c50 at gmail

Aug 12, 2009, 6:56 AM

Post #6 of 10 (505 views)
Permalink
Re: Django and Custom environment variables [In reply to]

> Django sites can help take a look at:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/sites/?from=olddocs#django.contrib.sites.django.contrib.sites.models.Site
>

Thank you, but Using Django isn't my issue.

I want to setup a custom environment variable on cherokee, and get the
value on my running website.

I just write a simple python script to run under cgi, adding a TEST
variable with the value TEST

#/usr/bin/env python
import os
print (os.environ['TEST'])

It raise an non key exception, How does work the custom environment
variables?

>
> saludos
>
>
> Leonel
>
>

--
Mario César Señoranis Ayala
Attachments: signature.asc (0.19 KB)


alvaro at octality

Aug 12, 2009, 9:00 AM

Post #7 of 10 (494 views)
Permalink
Re: Django and Custom environment variables [In reply to]

On 12-ago-09, at 15:56, Mario César Señoranis Ayala wrote:

> I want to setup a custom environment variable on cherokee, and get the
> value on my running website.

If you want to pass a set of variables to an Information Source
(FastCGI or SCGI), you have to define them in "Information Sources" ->
<Pick the one you wanna custom> -> "Add new Environment variable".

In case you'd like to pass a environment variable to a CGI (a complete
different thing), you'd have to go "Virtual Servers" -> <Pick the
vserver> -> "Behavior" -> <Pick the CGI rule> -> "Handler" -> "Custom
environment variables".

--
Octality
http://www.octality.com/

_______________________________________________
Cherokee mailing list
Cherokee [at] lists
http://lists.octality.com/listinfo/cherokee


mariocesar.c50 at gmail

Aug 12, 2009, 9:07 AM

Post #8 of 10 (502 views)
Permalink
Re: Django and Custom environment variables [In reply to]

El mié, 12-08-2009 a las 18:00 +0200, Alvaro Lopez Ortega escribió:
> On 12-ago-09, at 15:56, Mario César Señoranis Ayala wrote:
>
> > I want to setup a custom environment variable on cherokee, and get the
> > value on my running website.
>
> If you want to pass a set of variables to an Information Source
> (FastCGI or SCGI), you have to define them in "Information Sources" ->
> <Pick the one you wanna custom> -> "Add new Environment variable".
>
> In case you'd like to pass a environment variable to a CGI (a complete
> different thing), you'd have to go "Virtual Servers" -> <Pick the
> vserver> -> "Behavior" -> <Pick the CGI rule> -> "Handler" -> "Custom
> environment variables".

Thanks, I just try to setup the Environment Variable in the Information
Sources.

name TEST value TEST

Inside my Django project, I try this:

import os
print(os.environ['TEST'])

I get no value, I get the that key TEST doesn't exists.

> --
> Octality
> http://www.octality.com/
>

--
Mario César Señoranis Ayala

Twitter: http://twitter.com/mariocesar_bo
Arte: http://mariocesar.deviantart.com
Blog Software Libre: http://softwarelibre.org.bo/mariocesar
Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
Attachments: signature.asc (0.19 KB)


xiong.chiamiov at gmail

Aug 17, 2009, 2:12 PM

Post #9 of 10 (480 views)
Permalink
Re: Django and Custom environment variables [In reply to]

2009/8/11 Mario César Señoranis <mariocesar.c50 [at] gmail>

> I was trying to deploy a Django application for managing subdomains as
> specific apps, something like devianart.com for example. that
> username.domain.com trows the user dashboard instead the homepage of the
> website.
>
> So, I came with a solution, to chose the urls.py of the project making a
> difference if the user come from the main domain or a subdomain, if on
> the request I get the subdomain I load just an specific urls.py.
>
> In my 'plans' I need to to create a vhost for the main site, that
> catches the domain.com and www.domain.com, and another vhost that caches
> everything else *.domain.com, both vhost would have the same Information
> Source, to get the load of the urls.py be different I want to set
> something like a *custom* setting for each vhost, creating a Custom
> Environment variable in the SCGI handler.


My approach would be to have two separate vhosts (as you mentioned here)
with two slightly different information sources. For the subdomain one,
pass manage.py the --settings=[file] command to give it a different
settings.py. In that file, import all the settings from the default, and
override some variable with the value of the subdomain, obtained by
request.META['HTTP_HOST'], as Pablo suggested. I'd avoid mucking around
with environment variables entirely if I could avoid it. The calculation
here is minimal (especially if you use python regexes, which are compiled
only once), especially considering that there is already a decent amount of
overhead in the framework itself. One string-parsing operation isn't
anything to be concerned about, and if your site has the kind of traffic
where it is, you really shouldn't be using an interpreted language.

--
James Pearson
--
The best way to predict the future is to invent it.
- Alan Kay


mariocesar.c50 at gmail

Aug 17, 2009, 2:22 PM

Post #10 of 10 (479 views)
Permalink
Re: Django and Custom environment variables [In reply to]

El lun, 17-08-2009 a las 14:12 -0700, James Pearson escribió:
> 2009/8/11 Mario César Señoranis <mariocesar.c50 [at] gmail>
> I was trying to deploy a Django application for managing
> subdomains as
> specific apps, something like devianart.com for example. that
> username.domain.com trows the user dashboard instead the
> homepage of the
> website.
>
> So, I came with a solution, to chose the urls.py of the
> project making a
> difference if the user come from the main domain or a
> subdomain, if on
> the request I get the subdomain I load just an specific
> urls.py.
>
> In my 'plans' I need to to create a vhost for the main site,
> that
> catches the domain.com and www.domain.com, and another vhost
> that caches
> everything else *.domain.com, both vhost would have the same
> Information
> Source, to get the load of the urls.py be different I want to
> set
> something like a *custom* setting for each vhost, creating a
> Custom
> Environment variable in the SCGI handler.
>
> My approach would be to have two separate vhosts (as you mentioned
> here) with two slightly different information sources. For the
> subdomain one, pass manage.py the --settings=[file] command to give it
> a different settings.py. In that file, import all the settings from
> the default, and override some variable with the value of the
> subdomain, obtained by request.META['HTTP_HOST'], as Pablo suggested.
> I'd avoid mucking around with environment variables entirely if I
> could avoid it. The calculation here is minimal (especially if you
> use python regexes, which are compiled only once), especially
> considering that there is already a decent amount of overhead in the
> framework itself. One string-parsing operation isn't anything to be
> concerned about, and if your site has the kind of traffic where it is,
> you really shouldn't be using an interpreted language.

Thanks, I get realize that using the environment variable isn't such a
*good* idea. I am doing something like your advice.

Instead have just /project/manage.py

I create /projects/main/manage.py /projects/subdomains/manage.py

I load the same settings, but override some as the URL_CONF, so I get
two information server for each project that loads the same DB and share
some apps and give the *.domain.com to the subdomains project and
www.domain.com to the main project, with that and a middleware that
calculate the subdomain name on each http request, all the project get
done :)

I am still curious about the Environment Variable, cause It doesn't
behave as I expected. But it's not my concern any more. :)
Best Regards

> --
> James Pearson
> --
> The best way to predict the future is to invent it.
> - Alan Kay

--
Mario César Señoranis Ayala

Twitter: http://twitter.com/mariocesar_bo
Arte: http://mariocesar.deviantart.com
Blog Software Libre: http://softwarelibre.org.bo/mariocesar
Noticias Compartidas: http://tinyurl.com/mariocesar-shared-news
Attachments: signature.asc (0.19 KB)

Cherokee users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.