Re: Host a web application

2015-04-22 Thread Michele Mattioni
Hi,
if it is for a demo, you could use heroku to show it to your client:
https://www.heroku.com/

Best,
Michele

On Wed, Apr 22, 2015 at 7:24 AM, 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/CAC5ThKGDtC%2B6DrGB6P%3Dn3%3D90PeapaGWyjFSBkqr66UdaxNwpZw%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/CADDzk72OOq-G%3D%3Dx2MUUZWArY64PnvNEKi8PV2jkSnkvfNJ-A%2BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Serialize QuerySet Q (not the result)

2015-04-22 Thread guettli
Up to now only Q objects. If you know how to serialize aggregation / 
annotations, this would be great :-)

Am Dienstag, 21. April 2015 14:35:52 UTC+2 schrieb Vijay Khemlani:
>
> Do you only need to serialize Q objects? No aggregation / annotations?
>
> On Tue, Apr 21, 2015 at 8:00 AM, guettli > 
> wrote:
>
>>
>>
>> Am Montag, 20. April 2015 17:12:21 UTC+2 schrieb Vijay Khemlani:
>>>
>>> Are the queries associated with a certain form? Or they are arbitrary 
>>> queries?
>>>
>>>
>> Good question. I would prefer a solution which is not associated with a 
>> form. It is
>> only associated with a model.
>>
>> Otherwise it would be easy. I just need to store the input values of the 
>> form.
>>
>> I know that is very hard to make all filtering features available. But at 
>> least the basic
>> filtering should be serializable.
>>
>> Regards,
>>   Thomas Güttler
>>  
>>
>>> On Mon, Apr 20, 2015 at 10:01 AM, guettli  wrote:
>>>
 We want to store the QuerySet query (not the result) some how.

 Background: users should be able to save a complex query as "my 
 favorite query".

 Pickling querysets is possible, but version updates are not supported:

   
 https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets

 Simple queries (without OR) could be saved as dictionary.

 I have in mind some mini language which enables to store Q object 
 instances:

  Q(foo='bar', blu='bla') | Q(foo='x', blu='y')

 And ordering 

 Before reinventing the wheel, I want to ask if someone has seen or done
 something like this before.

 I could not find an existing project. But maybe I used the wrong 
 keywords for
 my favorite search engine.

 Regards,
   Thomas Güttler

 -- 
 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/3f75c38e-d2c9-480c-9103-e4ea1bad8f88%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...@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/a8cc7fc6-4969-4d88-b39f-bd1511cfed54%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/a4541c8f-9056-4e09-8a6b-a55fa2367b26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Serialize QuerySet Q (not the result)

2015-04-22 Thread Jani Tiainen
Hi,

Straight from the docs:  

https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets

"If you only want to pickle the necessary information to recreate the QuerySet 
from the database at a later time, pickle the query attribute of the QuerySet."

And in same place there even exists sample code how to restore pickled query.


On Wed, 22 Apr 2015 02:18:11 -0700 (PDT)
guettli  wrote:

> Up to now only Q objects. If you know how to serialize aggregation / 
> annotations, this would be great :-)
> 
> Am Dienstag, 21. April 2015 14:35:52 UTC+2 schrieb Vijay Khemlani:
> >
> > Do you only need to serialize Q objects? No aggregation / annotations?
> >
> > On Tue, Apr 21, 2015 at 8:00 AM, guettli > 
> > wrote:
> >
> >>
> >>
> >> Am Montag, 20. April 2015 17:12:21 UTC+2 schrieb Vijay Khemlani:
> >>>
> >>> Are the queries associated with a certain form? Or they are arbitrary 
> >>> queries?
> >>>
> >>>
> >> Good question. I would prefer a solution which is not associated with a 
> >> form. It is
> >> only associated with a model.
> >>
> >> Otherwise it would be easy. I just need to store the input values of the 
> >> form.
> >>
> >> I know that is very hard to make all filtering features available. But at 
> >> least the basic
> >> filtering should be serializable.
> >>
> >> Regards,
> >>   Thomas Güttler
> >>  
> >>
> >>> On Mon, Apr 20, 2015 at 10:01 AM, guettli  wrote:
> >>>
>  We want to store the QuerySet query (not the result) some how.
> 
>  Background: users should be able to save a complex query as "my 
>  favorite query".
> 
>  Pickling querysets is possible, but version updates are not supported:
> 
>    
>  https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets
> 
>  Simple queries (without OR) could be saved as dictionary.
> 
>  I have in mind some mini language which enables to store Q object 
>  instances:
> 
>   Q(foo='bar', blu='bla') | Q(foo='x', blu='y')
> 
>  And ordering 
> 
>  Before reinventing the wheel, I want to ask if someone has seen or done
>  something like this before.
> 
>  I could not find an existing project. But maybe I used the wrong 
>  keywords for
>  my favorite search engine.
> 
>  Regards,
>    Thomas Güttler
> 
>  -- 
>  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/3f75c38e-d2c9-480c-9103-e4ea1bad8f88%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...@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/a8cc7fc6-4969-4d88-b39f-bd1511cfed54%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/a4541c8f-9056-4e09-8a6b-a55fa2367b26%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Jani Tiainen

-- 
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-use

Re: django contrib auth last_login cannot be "null"

2015-04-22 Thread aRkadeFR

Indeed this was the problem.

Thanks for your answer and I got it through IRC too.

Have a good day

On 04/21/2015 07:13 PM, Tim Graham wrote:
This seems to be a common point of confusion. I'll add a sentence to 
release notes under the "``AbstractUser.last_login`` allows null 
values" section -- if this makes sense:


If you are using a custom user model, you'll need to run 
:djadmin:`makemigrations` and generate a migration for your app.


On Tuesday, April 21, 2015 at 12:27:57 PM UTC-4, aRkadeFR wrote:

Hello,

I'm upgrading my systems to Django 1.8 and I'm facing this error:
(1048, "Column 'last_login' cannot be null")

so I describe my table in DB:

+-+--+--+-+-++

| Field   | Type | Null | Key | Default |
Extra  |

+-+--+--+-+-++

| last_login  | datetime | NO   | | NULL
||


and yep, it is not nullable, but the 0005_alter_user_last_login_null
migrations
is run, so why this field is not nullable?
How can I debug this?

PS: I run ./manage.py migrate (without --fake option)
and I use the AbstractUser as my base class.

Thanks and have a good one



--
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/55376E27.6000208%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Customising widget widths in django-admin (using django-grappelli)

2015-04-22 Thread Vikas Rawal
 
  I have an admin form that is rather long (many models, over 150 fields). 
I use TabularInlines for most of these. I am unable to adjust width of 
various fields to reduce the overall width of the form. Since 
django-grappelli overrides widths specified in forms.py, the recommended 
way is to use css to adjust field width.

Something like this works for text fields
#member_set-group .grp-td.education_level .vTextField { width: 20em; }

And this for integer fields:
#member_set-group .grp-td.literacy_status .vIntegerField { width: 5em; }

I do not know what to use in place of .vTextField and .vIntegerField for 
fields that have a dropdown menu (either ChoiceFields, or dropdown menu 
coming from a ForeignKey relationship. For example, the 'sex' and 
'relationship' fields in the model below.

--
class member(models.Model):
sno = models.ForeignKey(Household)
person_number = models.IntegerField()
name = models.CharField(max_length=
150)
sex_choices = (
('M','Male'),
('F','Female'),
)
sex = models.CharField(max_length=3,choices=sex_choices)
age = models.CharField(max_length=30,blank=True)
relationship = models.ForeignKey(CodeRelationship, blank=True, 
null=True, on_delete=models.SET_NULL)
nearest_relative_member = models.IntegerField("Person number of nearest 
member relative", blank=True,null=True)
nearest_relative_name_if_non_member = models.CharField("Name of nearest 
relative, if not a household member",max_length=4,blank=True)
marital_status_choices = (
(1, 'Single'),
(2, 'Currently married'),
(3, 'Divorced/separated'),
(4, 'Widowed'),
)
marital_status = 
models.IntegerField(choices=marital_status_choices,blank=True)
literacy_status = models.IntegerField(null=True, blank=True)
education_level = models.CharField(max_length=150, blank=True)
name_and_location_educational_institution = 
models.ForeignKey(CodeEducationInstitution, blank=True, null=True, 
on_delete=models.SET_NULL)
comments = models.CharField(max_length=600, blank=True)

--

I also tried assigning custom css classes to each of the widgets in 
forms.py as follows:

--
class HouseholdMemberForm(forms.ModelForm):
  class Meta:
widgets = { 'person_number': forms.TextInput(attrs={'class': 'wide5'})
, 'name': forms.TextInput(attrs={'class': 'wide15'})
, 'sex': forms.ChoiceField(attrs={'class': 'wide5'})
, 'age': forms.TextInput(attrs={'class': 'wide5'})
, 'nearest_relative_member': 
forms.TextInput(attrs={'class': 'wide5'})
, 'nearest_relative_name_if_non_member': 
forms.TextInput(attrs={'class': 'wide5'})
, 'marital_status': forms.TextInput(attrs={'class': 
'wide5'})
, 'literacy_status': forms.TextInput(attrs={'class': 
'wide5'})
, 'education_level': forms.TextInput(attrs={'class': 
'wide15'})
, 'comments': forms.TextInput(attrs={'class': 'wide5'})
}

-

If I could set the width of all fields with css class wide5 to 5em, the job 
will become much simpler, since I would not need to specify width to each 
field individually.

But the following has no effect.

#member_set-group .wide5 { width: 35px;
  padding: 1px;  
  }

Would appreciate if somebody could guide me here.

VR

-- 
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/0a5b7df7-5410-4c8c-9e05-c1615dcca7b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: python / django demand

2015-04-22 Thread Malhar Vora
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+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/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/CAFA4AP8ucEM2JcTEetrsYRT5dritHNuoyjV5e64MuU%2BcDhvhiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Tutorial 2 issue when creating super user on Windows 7

2015-04-22 Thread Johan Pretorius


When running the $python manage.py createsuperuser command the following is 
returned:
C:\Users\johanP\mysite>python manage.py cre
Username (leave blank to use 'johanp'):
Email address: jar...@gmail.com
Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
nit__.py", line 338, in execute_from_command_line
utility.execute()
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
nit__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
e.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
ment\commands\createsuperuser.py", line 50, in execute
return super(Command, self).execute(*args, **options)
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
e.py", line 441, in execute
output = self.handle(*args, **options)
  File "C:\Program Files\Python 3.5\lib\site-packages\djan
ment\commands\createsuperuser.py", line 124, in handle
password = getpass.getpass()
  File "C:\Program Files\Python 3.5\lib\getpass.py", line
msvcrt.putwch(c)
AttributeError: module 'msvcrt' has no attribute 'putwch'

The command picks up my AD credentials and doesn't request a password. I can 
create a super user in python using the following 
link:https://docs.djangoproject.com/en/1.8/topics/auth/default/
But the admin site won't start using this method.
I'm running Python 3.5, Django 1.8 on Windows 7 Professional.


I have posted it to https://bugs.python.org/issue24023 .


Any assistance would be greatly appreciated.

-- 
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/87280dca-11cf-4160--c32011f2494d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Form to create several objects with one-to-one relation

2015-04-22 Thread Ilya Kazakevich
Thank you, that may work, but I feel that I reinventing wheel here.

Actually, there are inline_formset  and CreateWithInlinesView  (from django 
extras) and they do exactly what I want, but they only support ForeignKey, 
not OneToOne. Looks like I need to extend them to support OneToOne.


On Wednesday, April 22, 2015 at 2:40:56 AM UTC+3, Vijay Khemlani wrote:
>
> What about and old-school DetailView?
>
> def get_context_data -> Creates the two forms and puts them in the context
>
> def post -> Validates and process the forms
>
>
>
> On Tue, Apr 21, 2015 at 7:41 PM, Ilya Kazakevich  > wrote:
>
>> Hello,
>>
>> I have several models with one-to-one relation. For example
>>
>> class Task(models.Model):
>> initial_comment = models.OneToOneField('Comment')
>># A pack of other fields
>>
>> class Comment(models.Model)
>> body = RichTextField()
>># A pack of other fields
>>
>>
>> I want to create "create view" based on form, that gives user ability to 
>> create task and initial comment there.
>>
>> 1) I can't use CreateView because it is based on only one model
>> 2) I can't use ModelForm because it is based on only one model
>> 3) I can create several forms, but I can't join them into one formset 
>> (forms are different)
>> 4) I feel "inlineformset_factory" (InlineFormSet) should be used here, 
>> but I am not sure it suits best. Is there any 3rd party Django app to do 
>> that?
>>
>> Sure I can create form myself, but I do not want to copy/paste all 
>> fields, their types, localized labels, validations and so on. I just want 
>> to list their names (like "fields" attibute).
>> If you wonder why do I need one-to-one: Comments are used heavily in 
>> other places and have different relations with different models.
>>
>> Thank you.
>>
>> Ilya.
>>
>>  -- 
>> 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/e5254d86-c237-4192-bf1e-4e2d96722a9f%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/2aef2c76-b940-40f0-bf56-fefabbceb824%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
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 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/ffdc58f3-e10c-46df-b14f-ec4bc02c0c70%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/5ba4b639-48df-4c3b-8fb8-00a1a166f58e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing some tests for new feature

2015-04-22 Thread Avraham Serour
you should ask this on the django developers mailing list, this is the
django users list

On Wed, Apr 22, 2015 at 5:06 PM, ST LEON  wrote:

> I want to contribute one new feature to Django (doing this first time).
>
> I reading this  and
> have one question.
>
> First, write tests. I want to improve work of ping_google()
> 
>  and
> add some new behavior.
>
> But I can't find any tests that cover this function.
>
> I think, that it might be here
> , but
> I can't find tests for *ping_google()*.
>
> So, what should I do? That test needs me to see, how they works, change
> some of them and write new ones.
>
> My changes aren't be so serious: just a very simple 2-3 new lines.
>
> Please, help.
>
> 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+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/1a427e10-c658-4382-88f7-75a96961e0b6%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/CAFWa6tKwCkwtP4Eu23UW4ULAUPsbUetoioGxwq%3DhN%2BHhT-X0gA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Writing some tests for new feature

2015-04-22 Thread ST LEON
I want to contribute one new feature to Django (doing this first time).

I reading this  and 
have one question.

First, write tests. I want to improve work of ping_google() 

 and 
add some new behavior. 

But I can't find any tests that cover this function. 

I think, that it might be here 
, but I 
can't find tests for *ping_google()*.

So, what should I do? That test needs me to see, how they works, change 
some of them and write new ones.

My changes aren't be so serious: just a very simple 2-3 new lines.

Please, help. 

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+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/1a427e10-c658-4382-88f7-75a96961e0b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Writing some tests for new feature

2015-04-22 Thread Tim Graham
There was some recent work done on allowing customizing the ping_google 
sitemap URL, but it wasn't completed: 
https://github.com/django/django/pull/3528

You could take inspiration from your tests from there.

On Wednesday, April 22, 2015 at 10:21:44 AM UTC-4, ST LEON wrote:
>
> I want to contribute one new feature to Django (doing this first time).
>
> I reading this  
> and 
> have one question.
>
> First, write tests. I want to improve work of ping_google() 
> 
>  and 
> add some new behavior. 
>
> But I can't find any tests that cover this function. 
>
> I think, that it might be here 
> , but 
> I can't find tests for *ping_google()*.
>
> So, what should I do? That test needs me to see, how they works, change 
> some of them and write new ones.
>
> My changes aren't be so serious: just a very simple 2-3 new lines.
>
> Please, help. 
>
> 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+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/1de315e4-2252-4c1b-b805-0da2f98a0c71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Host a web application

2015-04-22 Thread Mario R. Osorio


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.


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

2015-04-22 Thread Bill Freeman
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 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/ffdc58f3-e10c-46df-b14f-ec4bc02c0c70%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/5ba4b639-48df-4c3b-8fb8-00a1a166f58e%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/CAB%2BAj0sPORrPmAz4%3DPj1XvP2DFdwXYqLB_AEHw5y1ki4QYwLog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: upgrading from Django 1.6 and south to Django 1.8

2015-04-22 Thread aRkadeFR

Hey there,

maybe you found some answers in my other post:
"django contrib auth last_login cannot be "null""

Did you run makemigrations ?

For the upgrade, I suggest to you to do it minor
version to minor version.


On 04/20/2015 09:04 PM, Scott Hostovich wrote:

I'm upgrading from Django 1.6 and south to Django 1.8.

Following the instructions 
at: https://docs.djangoproject.com/en/1.8/topics/migrations/#upgrading-from-south 
seems to work initially but then realize that the user model wasn't 
updated: https://github.com/django/django/tree/1.8/django/contrib/auth/migrations. 



I am using a custom user model but it only tacks on a field and some 
properties. Anyone else come across this?

--
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/75e22f40-5beb-405c-8360-cb6a98e8f87f%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/5537BABA.2040607%40arkade.info.
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 Bill Freeman
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 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/ffdc58f3-e10c-46df-b14f-ec4bc02c0c70%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/

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

2015-04-22 Thread Bill Freeman
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 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/ffdc58f3-e10c-46df-b14f-ec4bc02c0c70%40googlegroups.com
>> 

Re: Serialize QuerySet Q (not the result)

2015-04-22 Thread Tom Evans
On Wed, Apr 22, 2015 at 10:27 AM, Jani Tiainen  wrote:
> Hi,
>
> Straight from the docs:
>
> https://docs.djangoproject.com/en/1.8/ref/models/querysets/#pickling-querysets
>
> "If you only want to pickle the necessary information to recreate the 
> QuerySet from the database at a later time, pickle the query attribute of the 
> QuerySet."
>
> And in same place there even exists sample code how to restore pickled query.
>

And one paragraph later it says:

"""
You can’t share pickles between versions

Pickles of QuerySets are only valid for the version of Django that was
used to generate them. If you generate a pickle using Django version
N, there is no guarantee that pickle will be readable with Django
version N+1.
"""

> Background: users should be able to save a complex query as "my favorite 
> query".
>
> Pickling querysets is possible, but version updates are not supported:

I think the OP is aware of this, and is looking for an alternate solution.

Cheers

Tom

-- 
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/CAFHbX1%2BoQaUTav-koRF2aGovEa_Pk_NiA4w4-jbdT8ZPm%2B6Ofg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: form.errors.as_json() returns a str - Django 1.8

2015-04-22 Thread Tom Evans
On Tue, Apr 21, 2015 at 4:57 PM, George L.  wrote:
> I'm trying to return errors to an ajax call but as_json() form method
> generates a string of a dict instead of a dict. JsonResponse accepts only
> dicts and if I set safe=False, JsonResponse tries to serialize the data as a
> string, which results in a corrupted data.
>
> Is this a bug or expected result?

Expected result. JSON is text, if it returned a dictionary, as_json()
wouldn't be a good name!

JsonResponse is a util for turning dictionaries into JSON, if you
actually have JSON strings, you could do something like this:

  json_rsp = HttpResponse(frm.as_json(), content_type='application/json')

Cheers

Tom

-- 
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/CAFHbX1LqCGu8hbCQEMt%2BN6ycLG%3DYS93WUtnzLjRNMXEjxypXEg%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 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 >