Re: generating pdf report with django-easy-pdf

2015-04-22 Thread sum abiut
Hi James,
Yes i have validated that there is  data in the govstaff variable. when i
add govstaff to context within the get_context_data() i am getting the
error non-keyword arg after keyword arg. Is there are other ways to
generated pdf reports on Django?

Cheers,

On Thu, Apr 23, 2015 at 12:34 PM, James Schneider 
wrote:

> Have you validated that there is actual data in the govstaff variable
> within your template? Nothing is going to show up if it is an empty
> variable or doesn't exist in your template context.
>
> While I'm not familiar with the package you're using, I suspect you need
> to add the govstaff variable to your context within the get_context_data()
> method in your view class. Otherwise your template has no idea what data
> you are trying to display.
>
> -James
> On Apr 22, 2015 6:16 PM, "sum abiut"  wrote:
>
>> Hi,
>> I am trying to generate pdf reports using django-easy-pdf
>>  but some
>> how i am not geting the data.
>>
>>
>> here is what i get. i only get the header but not the data.  i think i am
>> missing something from class viewpdfreport that i can't seem to figure it 
>> ou[image:
>> Inline image 1]
>>
>> Here is my view.py:
>>
>> from django.shortcuts import render
>> from django.shortcuts import render_to_response
>> from django.conf import settings
>> from django.views.generic import TemplateView
>> from eLeave.views import govoffice
>>
>> from eLeave.models import newleave
>>
>>
>> from easy_pdf.views import PDFTemplateView
>>
>> class viewpdfreport(PDFTemplateView):
>> template_name = "viewpdf.html"
>>
>> def get_context_data(self, **kwargs):
>> return super(viewpdfreport, self).get_context_data(
>> pagesize="A4",
>> title="Test!",
>> **kwargs
>> )
>>
>>
>>
>>
>> here is my viewpdf.html
>>
>> 
>> 
>> 
>>   First Name
>>   Last Name
>>   Position
>>   Department
>>   Month 
>>   Year
>>   Total leave consume
>>Current Leave Entitlement
>>Holidays
>>Weekend
>> Leave outstanding Balance
>>Leave current Balance
>>
>>
>> 
>> {%for a in govstaff%}
>> 
>> 
>> {{a.first_name}}
>>   {{a.last_name}}
>>   {{a.position}}
>>   {{a.department}}
>>   {{a.month}}
>>   {{a.year}}
>>   {{a.total_working_days}}
>>   {{a.leave_entitlement}}
>>   {{a.holiday}}
>>   {{a.weekend}}
>>   {{a.leave_outstanding_balance}}
>>   {{a.leave_current_balance}}
>>
>>
>>
>>   
>> {%endfor%}
>> 
>>
>>
>> this function is a view from a different app(view.py)
>> def govoffice(request):
>> govstaff=newleave.objects.filter(department="GOV",department_head_authorization="Approved")
>> return render(request,'viewpdf.html', locals())
>>
>>
>> Cheers,
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPCf-y4TC8oXGeE0q9vPcj%3Dnx9qXJ37Ac4PcZiW6cGgGKb-LJw%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUUy6WAnZBJcfg5jOJ7ofdBTOT6S%2B1wV5J2iX%3D6idGUbA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



--

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCf-y5aOsWtjkuR5e72yvzf46nivRyBDB5fQQJyXUorgE-nhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice for passing JSON objects to a template

2015-04-22 Thread Mario Gudelj
I often use method 2. I don't see a problem with it.

On 10 April 2015 at 02:08, Eric Plumb  wrote:

> Hi Djangoers!
>
> Sometimes in the course of human events it becomes necessary to encode a
> JSON object directly into a template.  We all prefer AJAX and REST APIs and
> the rest of the TOFLAs, but in the cases where it has to be part of the
> template, I'm wondering if there's an accepted canonical best-practice way
> to do so and remain safe from XSS attacks and other nastiness.
>
> I'm aware of the following two methods:
>
> 1. HTML attribute loaded by jQuery's $.data()
>
> # view
> return { ... {'my_obj': mark_safe(escape(json.dumps(obj))) } ... }
>
> # template
> ...
>
> # JS
> var myObj = $('div').data('my-object');  // implicitly calls JSON.parse()
> on the encoded object
>
> 2. Explicitly parsed JS object
>
> # view
> return { ... {'my_obj': mark_safe(escapejs(json.dumps(obj))) } ... }
>
> # template
> 
>   var myObj = JSON.parse('{{ my_obj }}')
> 
>
> Are there better methods?  It seems like this ought to come up often in
> building safe websites, but I don't see a consensus out there on the Web.
> Thanks in advance for your consideration!
>
> Eric
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9de1-d8c9-41a3-b86e-64e675c1eddf%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHqTbjnNzHF%3DDDFW4pLBApzdtnvwJLR8uConTUjmrSLVDSENbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Host a web application

2015-04-22 Thread Mario Gudelj
Sign up for AWS, fire up a free micro instance and host on that. You can
have it up there in no time with something like
https://github.com/gcollazo/Fabulous

On 23 April 2015 at 00:52, Mario R. Osorio  wrote:

>
>
> www.pythonanywhere.com made it easier for me to deploy than heroku
>
> On Wednesday, April 22, 2015 at 2:25:56 AM UTC-4, Kishan Mehta wrote:
>>
>> Hi ,
>>
>> I have to show my web application project work to a potential employer.
>> Is it possible to host the demo somewhere? Any guide on this?
>>
>> Thanks for help,
>> Kishankumar Mehta
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/109e5f89-bc99-48a4-a0cd-02ab86f79545%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHqTbjkui6fk1B01LDviPMKCBMz0FTgKN3UmXywmnAH1ZqScfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: generating pdf report with django-easy-pdf

2015-04-22 Thread James Schneider
Have you validated that there is actual data in the govstaff variable
within your template? Nothing is going to show up if it is an empty
variable or doesn't exist in your template context.

While I'm not familiar with the package you're using, I suspect you need to
add the govstaff variable to your context within the get_context_data()
method in your view class. Otherwise your template has no idea what data
you are trying to display.

-James
On Apr 22, 2015 6:16 PM, "sum abiut"  wrote:

> Hi,
> I am trying to generate pdf reports using django-easy-pdf
>  but some
> how i am not geting the data.
>
>
> here is what i get. i only get the header but not the data.  i think i am
> missing something from class viewpdfreport that i can't seem to figure it 
> ou[image:
> Inline image 1]
>
> Here is my view.py:
>
> from django.shortcuts import render
> from django.shortcuts import render_to_response
> from django.conf import settings
> from django.views.generic import TemplateView
> from eLeave.views import govoffice
>
> from eLeave.models import newleave
>
>
> from easy_pdf.views import PDFTemplateView
>
> class viewpdfreport(PDFTemplateView):
> template_name = "viewpdf.html"
>
> def get_context_data(self, **kwargs):
> return super(viewpdfreport, self).get_context_data(
> pagesize="A4",
> title="Test!",
> **kwargs
> )
>
>
>
>
> here is my viewpdf.html
>
> 
> 
> 
>   First Name
>   Last Name
>   Position
>   Department
>   Month 
>   Year
>   Total leave consume
>Current Leave Entitlement
>Holidays
>Weekend
> Leave outstanding Balance
>Leave current Balance
>
>
> 
> {%for a in govstaff%}
> 
> 
> {{a.first_name}}
>   {{a.last_name}}
>   {{a.position}}
>   {{a.department}}
>   {{a.month}}
>   {{a.year}}
>   {{a.total_working_days}}
>   {{a.leave_entitlement}}
>   {{a.holiday}}
>   {{a.weekend}}
>   {{a.leave_outstanding_balance}}
>   {{a.leave_current_balance}}
>
>
>
>   
> {%endfor%}
> 
>
>
> this function is a view from a different app(view.py)
> def govoffice(request):
> govstaff=newleave.objects.filter(department="GOV",department_head_authorization="Approved")
> return render(request,'viewpdf.html', locals())
>
>
> Cheers,
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPCf-y4TC8oXGeE0q9vPcj%3Dnx9qXJ37Ac4PcZiW6cGgGKb-LJw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUUy6WAnZBJcfg5jOJ7ofdBTOT6S%2B1wV5J2iX%3D6idGUbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


generating pdf report with django-easy-pdf

2015-04-22 Thread sum abiut
Hi,
I am trying to generate pdf reports using django-easy-pdf
 but some how
i am not geting the data.


here is what i get. i only get the header but not the data.  i think i am
missing something from class viewpdfreport that i can't seem to figure
it ou[image:
Inline image 1]

Here is my view.py:

from django.shortcuts import render
from django.shortcuts import render_to_response
from django.conf import settings
from django.views.generic import TemplateView
from eLeave.views import govoffice

from eLeave.models import newleave


from easy_pdf.views import PDFTemplateView

class viewpdfreport(PDFTemplateView):
template_name = "viewpdf.html"

def get_context_data(self, **kwargs):
return super(viewpdfreport, self).get_context_data(
pagesize="A4",
title="Test!",
**kwargs
)




here is my viewpdf.html




  First Name
  Last Name
  Position
  Department
  Month 
  Year
  Total leave consume
   Current Leave Entitlement
   Holidays
   Weekend
Leave outstanding Balance
   Leave current Balance



{%for a in govstaff%}


{{a.first_name}}
  {{a.last_name}}
  {{a.position}}
  {{a.department}}
  {{a.month}}
  {{a.year}}
  {{a.total_working_days}}
  {{a.leave_entitlement}}
  {{a.holiday}}
  {{a.weekend}}
  {{a.leave_outstanding_balance}}
  {{a.leave_current_balance}}



  
{%endfor%}



this function is a view from a different app(view.py)
def govoffice(request):
govstaff=newleave.objects.filter(department="GOV",department_head_authorization="Approved")
return render(request,'viewpdf.html', locals())


Cheers,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCf-y4TC8oXGeE0q9vPcj%3Dnx9qXJ37Ac4PcZiW6cGgGKb-LJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying understand static files.

2015-04-22 Thread john

Thanks guys - that worked!

I'm going to call it black magic - because to be truthful I don't 
understand how it really works.  If anyone has a better link than 
Django's on static files that explains what is really happening - it 
would be very helpful.


Johnf

On 04/22/2015 04:57 PM, Mike Dewhirst wrote:

On 23/04/2015 9:35 AM, john wrote:

Hi,
I have created a website that works well under "runserver".  But when I
use nginx and uwsgi the basic website comes up but it is missing the
static file information. I have run "manage.py collectstatic" but still
no static files are used.

Reading the Django doc's tells me that I need the webserver to serve the
static files.  Ok I think I can do that (maybe).  But I don't understand
completely.  In my templates I have links like:


How does the nginx server understand to provide the css file for my html
page from the code above?

I read that I can add a 'location' in the nginx config file but don't
understand how nginx would understand to provide it when my template is
called.


You probably want three locations ... here are mine:

location /static/ {
root/home/mike/envs/pq5/project;
access_log  off;
log_not_found   off;
}

location /robots.txt {
root/home/mike/envs/pq5/project/static;
access_log  off;
log_not_found   off;
}

location /favicon.ico {
root/home/mike/envs/pq5/project/static/img;
access_log  off;
log_not_found   off;

So whenever a client browser requests something prefixed by /static/ 
nginx sees that and substitutes the value of "root". Therefore, 
collectstatic has to put your css files exactly where your template 
says to look for them.


Collectstatic knows exactly where by checking the value in 
settings.STATIC_ROOT


hth

mike



Thanks for the help in advance.

Johnf






--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55383875.6020900%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying understand static files.

2015-04-22 Thread Mike Dewhirst

On 23/04/2015 9:35 AM, john wrote:

Hi,
I have created a website that works well under "runserver".  But when I
use nginx and uwsgi the basic website comes up but it is missing the
static file information. I have run "manage.py collectstatic" but still
no static files are used.

Reading the Django doc's tells me that I need the webserver to serve the
static files.  Ok I think I can do that (maybe).  But I don't understand
completely.  In my templates I have links like:


How does the nginx server understand to provide the css file for my html
page from the code above?

I read that I can add a 'location' in the nginx config file but don't
understand how nginx would understand to provide it when my template is
called.


You probably want three locations ... here are mine:

location /static/ {
root/home/mike/envs/pq5/project;
access_log  off;
log_not_found   off;
}

location /robots.txt {
root/home/mike/envs/pq5/project/static;
access_log  off;
log_not_found   off;
}

location /favicon.ico {
root/home/mike/envs/pq5/project/static/img;
access_log  off;
log_not_found   off;

So whenever a client browser requests something prefixed by /static/ 
nginx sees that and substitutes the value of "root". Therefore, 
collectstatic has to put your css files exactly where your template says 
to look for them.


Collectstatic knows exactly where by checking the value in 
settings.STATIC_ROOT


hth

mike



Thanks for the help in advance.

Johnf




--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55383587.4010203%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Trying understand static files.

2015-04-22 Thread john
Thanks that helps with the nginx configure file.  But what I don't 
understand is how the template tells nginx what to serve?  There has to 
be some sort of black magic here!  As I understand the process - the 
client asks for a page - django routes via urls - it finds the template 
and processes it - uses the static file location - django grabs the 
static file and sends it.  How does Nginx know what to do?


Being a newbie - I'd like to understand why I'm adding a 'locaiton' and 
how the nginx becomes aware that it is needed.


On 04/22/2015 04:47 PM, Lachlan Musicman wrote:

Oh my aching head and static files.

STATIC_URL points to the namespace that the files will be served from:
eg mydomain.com/static
To set this up, in nginx/apache you need a stanza that looks like:

  location /static {
  alias /var/www/trees/opentrees/static;
}

STATIC_ROOT is where those files are served from - in this case,
/var/www/trees/opentrees/static
This is also where collectstatic *puts* the files it finds when it's
run. This directory, apparently (I discovered last night), should
never
be in your version control (git, svn, hg)

STATICFILES_DIRS *is* in your version control. Each of these
directories should be listed. This is where collectstatic *finds*
static files to copy to STATIC_ROOT,
Your proj/app structure looks like this:

proj/static
proj/app/static

Add each of these to STATICFILES_DIRS.

Admin, and other pip installed apps, will automatically be included (I think).

I hope this helps.

cheers
L.
--

I'm treading carefully
but it's the time of night
the snowy light
the subway roar
and the whispered fights
exciting sights
but it's not enough
I thought it was
I wish it was
I thought it was
-
You name it - The Cannanes with Explosion Robinson.


On 23 April 2015 at 09:35, john  wrote:

Hi,
I have created a website that works well under "runserver".  But when I use
nginx and uwsgi the basic website comes up but it is missing the static file
information. I have run "manage.py collectstatic" but still no static files
are used.

Reading the Django doc's tells me that I need the webserver to serve the
static files.  Ok I think I can do that (maybe).  But I don't understand
completely.  In my templates I have links like:


How does the nginx server understand to provide the css file for my html
page from the code above?

I read that I can add a 'location' in the nginx config file but don't
understand how nginx would understand to provide it when my template is
called.

Thanks for the help in advance.

Johnf


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5538303D.2080202%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55383516.5000506%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange error in django

2015-04-22 Thread Vijay Khemlani
What specific version of Python are you using (2.7...x?)

On Wed, Apr 22, 2015 at 8:26 PM, John DeRosa 
wrote:

> Oh, sorry.
>
> Well, you’re using joblib. The joblib.load() call loads something and
> return a Python object into the symbol clf.
>
> It would seem you need to look at the object that joblib.load is
> reconstituting. This code snippet doesn’t give enough information to
> diagnose this, but if I were you, I’d probably try this:
>
> 1. What file does "joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name,
> classifier_name))” read, and what object does it return?
>
> 2. Can you interactively run this code in the Python interpreter? Does it
> run OK, or does it throw an exception?
>
> 3. If it works on your development machine, try running it interactively
> on your production machine. Ssh into your production server and run the
> code.
>
> 4. What does dir(clf) return? Does the clf object have the methods you
> expect it to have?
>
>
> If you can get it to throw an exception when you run it from the
> interactive prompt, you can single-step it.
>
> John
>
>
> On Apr 22, 2015, at 4:10 PM, Cristian Javier Martinez <
> martinezcristianjav...@gmail.com> wrote:
>
> Thanks for your reply John DeRosa but the question is about what is
> causing the exception because I'm not using threads at all and the error
> says "*'Thread' object has no attribute '_children'"*. I'm catching the
> error and printing it out before the return as you can see in the log.
>
> El miércoles, 22 de abril de 2015, 19:13:55 (UTC-3), John DeRosa escribió:
>>
>> If you get an exception, the “except” clause will drop down into the
>> “return” statement, and classification_serializer will be referenced before
>> it’s assigned to. (Because it never was assigned to.)
>>
>> John
>>
>> On Apr 22, 2015, at 2:36 PM, Cristian Javier Martinez <
>> martinezcri...@gmail.com> wrote:
>>
>> Hi! I'm using the django rest framework and successfully deployed an
>> application in a production environment but I'm having an strange error
>> related to threads when I call a method that performs a simple
>> classification task (using a scikit learn classifier) and I have no idea
>> what is causing the error. This is the method in views.py
>>
>> @api_view(['GET', 'POST'])
>> def classify_item(request):
>> """
>> Classify item, or list classifications.
>> """
>> if request.method == 'GET':
>> items = Item.objects.all()
>> serializer = ItemSerializer(items, many=True)
>> return Response(serializer.data)
>>
>> elif request.method == 'POST':
>> serializer = ItemSerializer(data=request.data['item'])
>> if serializer.is_valid():
>> try:
>> item = serializer.data
>> filter_name = request.data['filter']
>>
>>
>> # fix encoding
>> item_dict =  {}
>> for key in item:
>> value = item[key]
>> if isinstance(value, unicode):
>> value =
>> value.encode('utf-8')
>> item_dict[key] = value
>>
>> classifier_name =
>> CLASSIFIER_NAME_BY_FILTER[filter_name]
>>
>> logger.debug("retrieving the persisted
>> classifier and classifing the item")
>> clf =
>> joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, classifier_name))
>>
>> logger.debug("predicting probabilities")
>> data = pd.DataFrame([item_dict])
>>
>> logger.debug("scoring item")
>> score = clf.predict(data)[0][1]
>>
>> logger.debug("score: {}".format(score))
>>
>>
>> # create and save classification
>> classification =
>> Classification(classifier_name=classifier_name,score=score,item_id=item['_id'])
>> classification_serializer =
>> ClassificationSerializer(classification)
>> #classification_serializer.save()
>> except Exception as e:
>> logger.error("Ocurrio un error al
>> intentar parsear el item: {}".format(e))
>> return Response(classification_serializer.data,
>> status=status.HTTP_201_CREATED)
>>
>> return Response(serializer.errors,
>> status=status.HTTP_400_BAD_REQUEST)
>>
>> And the output is:
>>
>> [22/Apr/2015 21:14:56] DEBUG [classifiers.views:63] retrieve the
>> classifier for the given sited_id and classify item
>> [22/Apr/2015 21:15:14] 

Re: Trying understand static files.

2015-04-22 Thread Lachlan Musicman
Oh my aching head and static files.

STATIC_URL points to the namespace that the files will be served from:
eg mydomain.com/static
To set this up, in nginx/apache you need a stanza that looks like:

 location /static {
 alias /var/www/trees/opentrees/static;
   }

STATIC_ROOT is where those files are served from - in this case,
/var/www/trees/opentrees/static
This is also where collectstatic *puts* the files it finds when it's
run. This directory, apparently (I discovered last night), should
never
be in your version control (git, svn, hg)

STATICFILES_DIRS *is* in your version control. Each of these
directories should be listed. This is where collectstatic *finds*
static files to copy to STATIC_ROOT,
Your proj/app structure looks like this:

proj/static
proj/app/static

Add each of these to STATICFILES_DIRS.

Admin, and other pip installed apps, will automatically be included (I think).

I hope this helps.

cheers
L.
--

I'm treading carefully
but it's the time of night
the snowy light
the subway roar
and the whispered fights
exciting sights
but it's not enough
I thought it was
I wish it was
I thought it was
-
You name it - The Cannanes with Explosion Robinson.


On 23 April 2015 at 09:35, john  wrote:
> Hi,
> I have created a website that works well under "runserver".  But when I use
> nginx and uwsgi the basic website comes up but it is missing the static file
> information. I have run "manage.py collectstatic" but still no static files
> are used.
>
> Reading the Django doc's tells me that I need the webserver to serve the
> static files.  Ok I think I can do that (maybe).  But I don't understand
> completely.  In my templates I have links like:
> 
>
> How does the nginx server understand to provide the css file for my html
> page from the code above?
>
> I read that I can add a 'location' in the nginx config file but don't
> understand how nginx would understand to provide it when my template is
> called.
>
> Thanks for the help in advance.
>
> Johnf
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5538303D.2080202%40jfcomputer.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiPW8UcBs2cb5mcXDUg0iUJ5-1tyHijU%3DkV8gKWrvo0-dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying understand static files.

2015-04-22 Thread Aaron C. de Bruyn
Have you looked through the deployment documentation yet?
(https://docs.djangoproject.com/en/1.8/howto/deployment/)

-A

On Wed, Apr 22, 2015 at 4:35 PM, john  wrote:
> Hi,
> I have created a website that works well under "runserver".  But when I use
> nginx and uwsgi the basic website comes up but it is missing the static file
> information. I have run "manage.py collectstatic" but still no static files
> are used.
>
> Reading the Django doc's tells me that I need the webserver to serve the
> static files.  Ok I think I can do that (maybe).  But I don't understand
> completely.  In my templates I have links like:
> 
>
> How does the nginx server understand to provide the css file for my html
> page from the code above?
>
> I read that I can add a 'location' in the nginx config file but don't
> understand how nginx would understand to provide it when my template is
> called.
>
> Thanks for the help in advance.
>
> Johnf
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5538303D.2080202%40jfcomputer.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEE%2BrGoERBV7%3DsQ2H%3DcDEKf01KkrBqcCKWrvoBx-SHqQR0B5nQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Trying understand static files.

2015-04-22 Thread john

Hi,
I have created a website that works well under "runserver".  But when I 
use nginx and uwsgi the basic website comes up but it is missing the 
static file information. I have run "manage.py collectstatic" but still 
no static files are used.


Reading the Django doc's tells me that I need the webserver to serve the 
static files.  Ok I think I can do that (maybe).  But I don't understand 
completely.  In my templates I have links like:



How does the nginx server understand to provide the css file for my html 
page from the code above?


I read that I can add a 'location' in the nginx config file but don't 
understand how nginx would understand to provide it when my template is 
called.


Thanks for the help in advance.

Johnf


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5538303D.2080202%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange error in django

2015-04-22 Thread John DeRosa
Oh, sorry.

Well, you’re using joblib. The joblib.load() call loads something and return a 
Python object into the symbol clf.

It would seem you need to look at the object that joblib.load is 
reconstituting. This code snippet doesn’t give enough information to diagnose 
this, but if I were you, I’d probably try this:

1. What file does "joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, 
classifier_name))” read, and what object does it return?

2. Can you interactively run this code in the Python interpreter? Does it run 
OK, or does it throw an exception?

3. If it works on your development machine, try running it interactively on 
your production machine. Ssh into your production server and run the code.

4. What does dir(clf) return? Does the clf object have the methods you expect 
it to have?


If you can get it to throw an exception when you run it from the interactive 
prompt, you can single-step it.

John


> On Apr 22, 2015, at 4:10 PM, Cristian Javier Martinez 
>  wrote:
> 
> Thanks for your reply John DeRosa but the question is about what is causing 
> the exception because I'm not using threads at all and the error says 
> "'Thread' object has no attribute '_children'". I'm catching the error and 
> printing it out before the return as you can see in the log.
> 
> El miércoles, 22 de abril de 2015, 19:13:55 (UTC-3), John DeRosa escribió:
> If you get an exception, the “except” clause will drop down into the “return” 
> statement, and classification_serializer will be referenced before it’s 
> assigned to. (Because it never was assigned to.)
> 
> John
> 
>> On Apr 22, 2015, at 2:36 PM, Cristian Javier Martinez 
>>  wrote:
>> 
>> Hi! I'm using the django rest framework and successfully deployed an 
>> application in a production environment but I'm having an strange error 
>> related to threads when I call a method that performs a simple 
>> classification task (using a scikit learn classifier) and I have no idea 
>> what is causing the error. This is the method in views.py
>> 
>> @api_view(['GET', 'POST'])
>> def classify_item(request):
>> """
>> Classify item, or list classifications.
>> """
>> if request.method == 'GET':
>> items = Item.objects.all()
>> serializer = ItemSerializer(items, many=True)
>> return Response(serializer.data)
>> 
>> elif request.method == 'POST':
>> serializer = ItemSerializer(data=request.data['item'])
>> if serializer.is _valid():
>> try:
>> item = serializer.data
>> filter_name = request.data['filter']
>> 
>> 
>> # fix encoding
>> item_dict =  {}
>> for key in item:
>> value = item[key]
>> if isinstance(value, unicode):
>> value = value.encode('utf-8')
>> item_dict[key] = value
>> 
>> classifier_name = 
>> CLASSIFIER_NAME_BY_FILTER[filter_name]
>> 
>> logger.debug("retrieving the persisted 
>> classifier and classifing the item")
>> clf = 
>> joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, classifier_name))
>> 
>> logger.debug("predicting probabilities")
>> data = pd.DataFrame([item_dict])
>> 
>> logger.debug("scoring item")
>> score = clf.predict(data)[0][1]
>> 
>> logger.debug("score: {}".format(score))
>> 
>> 
>> # create and save classification
>> classification = 
>> Classification(classifier_name=classifier_name,score=score,item_id=item['_id'])
>> classification_serializer = 
>> ClassificationSerializer(classification)
>> #classification_serializer.save()
>> except Exception as e:
>> logger.error("Ocurrio un error al intentar 
>> parsear el item: {}".format(e))
>> return Response(classification_serializer.data, 
>> status=status.HTTP_201_CREATED)
>> 
>> return Response(serializer.errors, 
>> status=status.HTTP_400_BAD_REQUEST)
>> 
>> And the output is:
>> 
>> [22/Apr/2015 21:14:56] DEBUG [classifiers.views:63] retrieve the classifier 
>> for the given sited_id and classify item
>> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:66] predicting probabilities
>> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:69] scoring item
>> 

Re: Strange error in django

2015-04-22 Thread Cristian Javier Martinez
Thanks for your reply John DeRosa but the question is about what is causing 
the exception because I'm not using threads at all and the error says 
"*'Thread' 
object has no attribute '_children'"*. I'm catching the error and printing 
it out before the return as you can see in the log.

El miércoles, 22 de abril de 2015, 19:13:55 (UTC-3), John DeRosa escribió:
>
> If you get an exception, the “except” clause will drop down into the 
> “return” statement, and classification_serializer will be referenced before 
> it’s assigned to. (Because it never was assigned to.)
>
> John
>
> On Apr 22, 2015, at 2:36 PM, Cristian Javier Martinez <
> martinezcri...@gmail.com > wrote:
>
> Hi! I'm using the django rest framework and successfully deployed an 
> application in a production environment but I'm having an strange error 
> related to threads when I call a method that performs a simple 
> classification task (using a scikit learn classifier) and I have no idea 
> what is causing the error. This is the method in views.py
>
> @api_view(['GET', 'POST'])
> def classify_item(request):
> """
> Classify item, or list classifications.
> """
> if request.method == 'GET':
> items = Item.objects.all()
> serializer = ItemSerializer(items, many=True)
> return Response(serializer.data)
>
> elif request.method == 'POST':
> serializer = ItemSerializer(data=request.data['item'])
> if serializer.is_valid():
> try:
> item = serializer.data
> filter_name = request.data['filter']
>
>
> # fix encoding
> item_dict =  {}
> for key in item:
> value = item[key]
> if isinstance(value, unicode):
> value = 
> value.encode('utf-8')
> item_dict[key] = value
>
> classifier_name = 
> CLASSIFIER_NAME_BY_FILTER[filter_name]
>
> logger.debug("retrieving the persisted 
> classifier and classifing the item")
> clf = 
> joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, classifier_name))
>
> logger.debug("predicting probabilities")
> data = pd.DataFrame([item_dict])
>
> logger.debug("scoring item")
> score = clf.predict(data)[0][1]
>
> logger.debug("score: {}".format(score))
>
>
> # create and save classification
> classification = 
> Classification(classifier_name=classifier_name,score=score,item_id=item['_id'])
> classification_serializer = 
> ClassificationSerializer(classification)
> #classification_serializer.save()
> except Exception as e:
> logger.error("Ocurrio un error al intentar 
> parsear el item: {}".format(e))
> return Response(classification_serializer.data, 
> status=status.HTTP_201_CREATED)
>
> return Response(serializer.errors, 
> status=status.HTTP_400_BAD_REQUEST)
>
> And the output is:
>
> [22/Apr/2015 21:14:56] DEBUG [classifiers.views:63] retrieve the 
> classifier for the given sited_id and classify item
> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:66] predicting 
> probabilities
> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:69] scoring item
> [22/Apr/2015 21:15:14] ERROR [classifiers.views:80] Ocurrio un error al 
> intentar parsear el item: *'Thread' object has no attribute '_children'*
> [22/Apr/2015 21:15:14] ERROR [django.request:256] Internal Server Error: 
> /items/
> Traceback (most recent call last):
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/core/handlers/base.py",
>  
> line 132, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/newrelic-2.50.0.39/newrelic/hooks/framework_django.py",
>  
> line 499, in wrapper
> return wrapped(*args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py",
>  
> line 58, in wrapped_view
> return view_func(*args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/generic/base.py",
>  
> line 71, in view
> return self.dispatch(request, *args, **kwargs)
>   File 
> 

Re: Strange error in django

2015-04-22 Thread John DeRosa
If you get an exception, the “except” clause will drop down into the “return” 
statement, and classification_serializer will be referenced before it’s 
assigned to. (Because it never was assigned to.)

John

> On Apr 22, 2015, at 2:36 PM, Cristian Javier Martinez 
>  wrote:
> 
> Hi! I'm using the django rest framework and successfully deployed an 
> application in a production environment but I'm having an strange error 
> related to threads when I call a method that performs a simple classification 
> task (using a scikit learn classifier) and I have no idea what is causing the 
> error. This is the method in views.py
> 
> @api_view(['GET', 'POST'])
> def classify_item(request):
> """
> Classify item, or list classifications.
> """
> if request.method == 'GET':
> items = Item.objects.all()
> serializer = ItemSerializer(items, many=True)
> return Response(serializer.data)
> 
> elif request.method == 'POST':
> serializer = ItemSerializer(data=request.data['item'])
> if serializer.is_valid():
> try:
> item = serializer.data
> filter_name = request.data['filter']
> 
> 
> # fix encoding
> item_dict =  {}
> for key in item:
> value = item[key]
> if isinstance(value, unicode):
> value = value.encode('utf-8')
> item_dict[key] = value
> 
> classifier_name = 
> CLASSIFIER_NAME_BY_FILTER[filter_name]
> 
> logger.debug("retrieving the persisted 
> classifier and classifing the item")
> clf = 
> joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, classifier_name))
> 
> logger.debug("predicting probabilities")
> data = pd.DataFrame([item_dict])
> 
> logger.debug("scoring item")
> score = clf.predict(data)[0][1]
> 
> logger.debug("score: {}".format(score))
> 
> 
> # create and save classification
> classification = 
> Classification(classifier_name=classifier_name,score=score,item_id=item['_id'])
> classification_serializer = 
> ClassificationSerializer(classification)
> #classification_serializer.save()
> except Exception as e:
> logger.error("Ocurrio un error al intentar 
> parsear el item: {}".format(e))
> return Response(classification_serializer.data, 
> status=status.HTTP_201_CREATED)
> 
> return Response(serializer.errors, 
> status=status.HTTP_400_BAD_REQUEST)
> 
> And the output is:
> 
> [22/Apr/2015 21:14:56] DEBUG [classifiers.views:63] retrieve the classifier 
> for the given sited_id and classify item
> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:66] predicting probabilities
> [22/Apr/2015 21:15:14] DEBUG [classifiers.views:69] scoring item
> [22/Apr/2015 21:15:14] ERROR [classifiers.views:80] Ocurrio un error al 
> intentar parsear el item: 'Thread' object has no attribute '_children'
> [22/Apr/2015 21:15:14] ERROR [django.request:256] Internal Server Error: 
> /items/
> Traceback (most recent call last):
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/core/handlers/base.py",
>  line 132, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/newrelic-2.50.0.39/newrelic/hooks/framework_django.py",
>  line 499, in wrapper
> return wrapped(*args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py",
>  line 58, in wrapped_view
> return view_func(*args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/generic/base.py",
>  line 71, in view
> return self.dispatch(request, *args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/newrelic-2.50.0.39/newrelic/hooks/component_djangorestframework.py",
>  line 27, in _nr_wrapper_APIView_dispatch_
> return wrapped(*args, **kwargs)
>   File 
> "/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/rest_framework/views.py",
>  line 452, in dispatch
> response = self.handle_exception(exc)
>   File 
> 

Strange error in django

2015-04-22 Thread Cristian Javier Martinez
Hi! I'm using the django rest framework and successfully deployed an 
application in a production environment but I'm having an strange error 
related to threads when I call a method that performs a simple 
classification task (using a scikit learn classifier) and I have no idea 
what is causing the error. This is the method in views.py

@api_view(['GET', 'POST'])
def classify_item(request):
"""
Classify item, or list classifications.
"""
if request.method == 'GET':
items = Item.objects.all()
serializer = ItemSerializer(items, many=True)
return Response(serializer.data)

elif request.method == 'POST':
serializer = ItemSerializer(data=request.data['item'])
if serializer.is_valid():
try:
item = serializer.data
filter_name = request.data['filter']


# fix encoding
item_dict =  {}
for key in item:
value = item[key]
if isinstance(value, unicode):
value = 
value.encode('utf-8')
item_dict[key] = value

classifier_name = 
CLASSIFIER_NAME_BY_FILTER[filter_name]

logger.debug("retrieving the persisted 
classifier and classifing the item")
clf = 
joblib.load(os.path.join(CLASSIFIERS_PATH, filter_name, classifier_name))

logger.debug("predicting probabilities")
data = pd.DataFrame([item_dict])

logger.debug("scoring item")
score = clf.predict(data)[0][1]

logger.debug("score: {}".format(score))


# create and save classification
classification = 
Classification(classifier_name=classifier_name,score=score,item_id=item['_id'])
classification_serializer = 
ClassificationSerializer(classification)
#classification_serializer.save()
except Exception as e:
logger.error("Ocurrio un error al intentar 
parsear el item: {}".format(e))
return Response(classification_serializer.data, 
status=status.HTTP_201_CREATED)

return Response(serializer.errors, 
status=status.HTTP_400_BAD_REQUEST)

And the output is:

[22/Apr/2015 21:14:56] DEBUG [classifiers.views:63] retrieve the classifier 
for the given sited_id and classify item
[22/Apr/2015 21:15:14] DEBUG [classifiers.views:66] predicting probabilities
[22/Apr/2015 21:15:14] DEBUG [classifiers.views:69] scoring item
[22/Apr/2015 21:15:14] ERROR [classifiers.views:80] Ocurrio un error al 
intentar parsear el item: *'Thread' object has no attribute '_children'*
[22/Apr/2015 21:15:14] ERROR [django.request:256] Internal Server Error: 
/items/
Traceback (most recent call last):
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/core/handlers/base.py",
 
line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/newrelic-2.50.0.39/newrelic/hooks/framework_django.py",
 
line 499, in wrapper
return wrapped(*args, **kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/decorators/csrf.py",
 
line 58, in wrapped_view
return view_func(*args, **kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/django/views/generic/base.py",
 
line 71, in view
return self.dispatch(request, *args, **kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/newrelic-2.50.0.39/newrelic/hooks/component_djangorestframework.py",
 
line 27, in _nr_wrapper_APIView_dispatch_
return wrapped(*args, **kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/rest_framework/views.py",
 
line 452, in dispatch
response = self.handle_exception(exc)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/rest_framework/views.py",
 
line 449, in dispatch
response = handler(request, *args, **kwargs)
  File 
"/home/keepcon/meli_filters_env/local/lib/python2.7/site-packages/rest_framework/decorators.py",
 
line 50, in handler
return func(*args, **kwargs)
  File "/home/keepcon/meli_filters/classifiers/views.py", line 81, in 
classify_item
return Response(classification_serializer.data, 
status=status.HTTP_201_CREATED)
UnboundLocalError: local variable 'classification_serializer' 

Re: Django Server Deployment - OperationalError on shared hosting ASO

2015-04-22 Thread David F
Got it to work-- changed permissions of my shared part of the server using 
the bash:

chmod 755 .

thanks james for thinking through this with me

On Sunday, April 19, 2015 at 5:49:41 PM UTC-7, David F wrote:
>
> oh and yes-- I SSH into my part of the server that's how I'm able to do 
> all this :X the database file is in the project folder just... it's coming 
> up with that message when I try to open it in shell
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9fb99fc-ce8d-4fe4-92aa-735ff13e4144%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: python / django demand

2015-04-22 Thread Jay
thank you, good info.

On Wednesday, 22 April 2015 05:10:48 UTC-6, mlvora.2010 wrote:
>
> Hey Jay,
>
> I am Malhar Vora from India. I may not be a proper person to answer to 
> your question as I don't have much experience but since 5-6 years I am 
> observing that Python/Django is gaining momentum in Indian market. As a 
> developer I keep track of Python/Django companies to get a job. In last 2-3 
> years I have seen tremendous growth in this stack. 
>
> Mostly this stack is used by startups. At India some of the very 
> successful startups like Goibibbo and Taxiforsure uses Python/Django stack. 
> I daily get lot of job offers for same stack from startups. After launch of 
> OpenStack framework,  Python has become popular in market.
>
> Thank you,
>
> Regds,
> Malhar Vora
>
>
> Regds,
> *Malhar Vora*
> http://about.me/malhar.vora
>
>
> On Tue, Apr 21, 2015 at 11:50 PM, Jay  
> wrote:
>
>> Just curious if any long time python / django developers have seen an 
>> increase in the demand/growth/popularity of these skills? I run a dev team 
>> of python/django/aws developers building an ecommerce website and was 
>> curious about what people think the future brings for this stack.  
>> Continued improvement, tools and frameworks, modules, popularity, growth 
>> and demand?
>>
>>
>>   We are located in the south west USA so thats my direct market area.
>>
>>
>>
>> any comments appreciated.
>>
>> Thanks.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/1b5c1b62-69b2-4b99-8777-c2dc5e89e1bf%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c1bef9bc-980e-40a0-a514-5afb9d9b98de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Serving / out of static directory, /api for Django DRF services (development/runserver/DEBUG mode)

2015-04-22 Thread LiteWait
Thank you. That is a perfect solution.

On Wednesday, April 22, 2015 at 11:26:00 AM UTC-4, ke1g wrote:
>
> And I probably would have gone with:
>
> from django.conf import settings
> if settings.DEBUG:
> urlpatterns += patterns(
> 'django.contrib.staticfiles.views',
> url(r'^$', 'serve', kwargs={'path': 'index.html'}),
> url(r'^(?P.*)$', 'serve'),
>
> The second url patter above must be the last one overall.  Any of your 
> other patters, for you Django views, for example, have already not matched 
> by the time this one gets tried.
>
>
> On Wed, Apr 22, 2015 at 11:17 AM, Bill Freeman  > wrote:
>
>> By the way, you can test whether the regular expression matches without 
>> getting Django involved, allowing for much quicker theories and tests.
>>
>> $ python
>> Python 2.7.3 (default, Jun  9 2014, 04:37:23) 
>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> import re
>> >>> re.match(r'^(?P(?:js|css|img)/.*)$', 'css/style.css')
>> <_sre.SRE_Match object at 0x7fb34977ddc8>
>> >>> _.groups()
>> ('css/style.css',)
>> >>> re.match(r'^(?P(?:js|css|img)/.*)$', 'apps/css/style.css')   # 
>> Does not match
>> >>> re.match(r'^(?P(?:js|css|img)/.*)$', 'apps/another.html')# 
>> Does not match
>> >>> re.match(r'^(?P(?:apps|js|css|img)/.*)$', 'apps/another.html')
>> <_sre.SRE_Match object at 0x7fb34977ddc8>
>> >>> _.groups()
>> ('apps/another.html',)
>> >>> 
>>
>> On Wed, Apr 22, 2015 at 11:06 AM, Bill Freeman > > wrote:
>>
>>> Are css and js subdirectries of apps as implied by the (as received) 
>>> indentation of your message?  Note that your "other" url pattern has js, 
>>> css, and img, but no apps.
>>>
>>> On Wed, Apr 22, 2015 at 9:28 AM, LiteWait >> > wrote:
>>>
 Well, this doesn't work completely. 

 Consider the (static) tree:

 /client
   index.html
   /apps
   another.html
   /css
   style.css
   /js
   my.js

 I need to serve this whole static tree out of /.


 On Tuesday, April 21, 2015 at 10:08:26 PM UTC-4, LiteWait wrote:
>
> I have no clue why this works, but I added the /client directory (full 
> path) to STATICFILE_DIRS and...
>
> from django.conf import settings
> if settings.DEBUG:
> urlpatterns += patterns(
> 'django.contrib.staticfiles.views',
> url(r'^(?:index.html)?$', 'serve', kwargs={'path': 'index.html'}),
> url(r'^(?P(?:js|css|img)/.*)$', 'serve'),
>
>
> Now /client/index.html is served up fine, as well as Django normal routes 
> like /admin, /api, etc. I really wish I understood this better.
>
>
>
> On Tuesday, April 21, 2015 at 4:02:24 PM UTC-4, ke1g wrote:
>>
>> That may work for most static things.  The question is whether the 
>> static server is happy with an empty path, assuming that you're trying 
>> to 
>> serve "/" this way.  If not, you might add a separate (earlier) pattern 
>> of 
>> r'^$' that specifies a path in the extra parameters dictionary (where 
>> you 
>> have 'document_root', and you may want it's document_root to be 
>> different 
>> to avoid serving the home page at two urls).
>>
>> On Tue, Apr 21, 2015 at 1:56 PM, LiteWait  wrote:
>>
>>> Planning to host the client side of our application in production 
>>> from a proxy to an S3 site from Nginx.
>>>
>>> The problem is we'd like to mimic this behavior by serving / in 
>>> Django runserver using a static directory url() entry.
>>>
>>> I've read over 
>>> https://docs.djangoproject.com/en/1.4/howto/static-files/#serving-other-directories
>>>  but 
>>> I can't seem to make Django route / to my client directory.
>>>
>>> Idea is I have a project directory* /client *which contains 
>>> index.html along with all the other files for site, and when I hit 
>>> http://127.0.0.1:8000/ I want to serve up 
>>> */client/index.html.*
>>>
>>> Not sure the following will work because I don't think you can't 
>>> have a STATIC_URL = '/', right?
>>>
>>> from django.contrib.staticfiles.urls import staticfiles_urlpatterns
>>> urlpatterns += staticfiles_urlpatterns()
>>>
>>>
>>> This one seems to make more sense, but I am not clear on what URL 
>>> pattern could pull this off..
>>>
>>> if settings.DEBUG:
>>>  urlpatterns += patterns('',
>>>  url(r'^(?P.*)$', 'django.views.static.serve', {
>>> 'document_root': '/client',}),
>>>  )
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, 
>>> send an 

Re: Best practice for passing JSON objects to a template

2015-04-22 Thread Ilya Kazakevich
What about putting it into ?

On Thursday, April 9, 2015 at 8:50:50 PM UTC+3, Eric Plumb wrote:
>
> Hi Djangoers!
>
> Sometimes in the course of human events it becomes necessary to encode a 
> JSON object directly into a template.  We all prefer AJAX and REST APIs and 
> the rest of the TOFLAs, but in the cases where it has to be part of the 
> template, I'm wondering if there's an accepted canonical best-practice way 
> to do so and remain safe from XSS attacks and other nastiness.
>
> I'm aware of the following two methods:
>
> 1. HTML attribute loaded by jQuery's $.data()
>
> # view
> return { ... {'my_obj': mark_safe(escape(json.dumps(obj))) } ... }
>
> # template
> 
...
> > # JS > var myObj = $('div').data('my-object'); // implicitly calls JSON.parse() > on the encoded object > > 2. Explicitly parsed JS object > > # view > return { ... {'my_obj': mark_safe(escapejs(json.dumps(obj))) } ... } > > # template >