Re: How to configure client side SSL trusted CA certificate ?

2017-02-08 Thread Pankaj Singh
Hi,

My question is where does SSL client code get the trusted CA certificates
> from, from Django, Python or the underlying OS?


As per official documentation of requests

library:

By default, Requests bundles a set of root CAs that it trusts, sourced from
> the Mozilla trust store. However, these are only updated once for each
> Requests version. This means that if you pin a Requests version your
> certificates can become extremely out of date.
>


>From Requests version 2.4.0 onwards, Requests will attempt to use
> certificates from certifi if it is present on the system. This allows for
> users to update their trusted certificates without having to change the
> code that runs on their system.
>


For the sake of security we recommend upgrading certifi frequently!


You can read more about certifi on it's official docs page
.

What configuration do I need in order for the SSL client to conduct the SSL
> handshake successfully?


You can set REQUESTS_CA_BUNDLE

environment
variable pointing to .cert file and it will pick it from there.

If you have just one `.crt` file which is self signed then you can do
following

export REQUESTS_CA_BUNDLE='~/Download/bar.example.com.cert'


But if you have multiple certificates which are self signed then you can
put them in a folder and set the folder path in environment variable. In
case of a folder, make sure to run c_rehash
 command for
folder.

mkdir -p /tmp/custom-certs
cp ~/Download/foo.example.com.cert /tmp/custom-certs
cp ~/Download/bar.example.com.cert /tmp/custom-certsexport
REQUESTS_CA_BUNDLE='/tmp/custom-certs'


Relevant source code in requests library:
https://github.com/kennethreitz/requests/blob/v2.13.0/requests/sessions.py#L658-L662


On Tue, Feb 7, 2017 at 10:30 PM, Gang Yang  wrote:

> Hi,
>
> I'm pretty new to Django and encountered some client side SSL issue. I'm
> trying to use django-cas-ng (CAS client) to do CAS authentication and the
> CAS server is using a self-signed server certificate. After obtaining the
> service ticket (ST), django-cas-ng tried to verify the ST by calling
> requests.get(...) and failed with CERTIFICATE_VERIFY_FAILED error.
> Following some suggestions on the internet, I've tried to modify
> django-cas-ng's code to call requests.get(..) with verify parameter, such
> as requests.get(..., verify=False) and requests.get(..., verify="CAS server
> cert"). Both workarounds worked, but I can't change third-party package
> code. I also tried to add the CAS server cert to the underlying OS (Windows
> 2008 and CentOS 6.7), but it did not help.
>
> My question is where does SSL client code get the trusted CA certificates
> from, from Django, Python or the underlying OS? What configuration do I
> need in order for the SSL client to conduct the SSL handshake successfully?
>
> Appreciate any help!
>
> Gang
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/f07875b8-f3b8-4bcb-b95f-2d936f5ece34%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Regards,
Pankaj Kumar Singh

Mobile: +91 9618754327
Skype: psjinx
Emal: psj...@gmail.com

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPLvEUY6nxY%2BJFswe75jrqh7MFG3DBtr2C%3DJGBrQVFAxSpSGBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Logs bloated by template variable not found in DEBUG level

2017-02-08 Thread Florian Perrodin
Dear all,

What is the proper way of checking if a variable exists in django?
To my knowledge, the proper way is to use the {% if var %} tag. If this is 
the case, it should not trigger a print in the output (even in the debug 
log level). Hereafter is an example:

# Note: django 1.10.2
from django.template import Context, Template

context = Context({})
template = Template("{% if avar %}bla{% endif %}")

# output
##
DEBUG 2017-02-08 10:19:14,844 base 3090 139658596226880 Exception while 
resolving variable 'avar' in template 'unknown'.
Traceback (most recent call last):
  File "***/python3.4/site-packages/django/template/base.py", line 885, in 
_resolve_lookup
current = current[bit]
  File "***site-packages/django/template/context.py", line 75, in 
__getitem__
raise KeyError(key)
KeyError: 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 891, in 
_resolve_lookup
if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'Context' has no attribute 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 900, in 
_resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 907, in 
_resolve_lookup
(bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [avar] in 
"[{'True': True, 'False': False, 'None': None}, {}]"
##

I however agree that the following code should generate an debug trace

from django.template import Context, Template

context = Context({})
template = Template("{{ avar }}")


Is there a workaround? Another way to check properly if a variable exists? 
- Note that I want to see other DEBUG messages, so I don't want to change 
the log level

Best regards

Florian


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8cfc93e-3426-48a9-ab77-5154f496f9a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to configure client side SSL trusted CA certificate ?

2017-02-08 Thread Pankaj Singh
I forgot to put c_rehash command in the example in my last reply. Here it
goes:

mkdir -p /tmp/custom-certs
cp ~/Download/foo.example.com.cert /tmp/custom-certs
cp ~/Download/bar.example.com.cert /tmp/custom-certs
c_rehash /tmp/custom-certsexport REQUESTS_CA_BUNDLE='/tmp/custom-certs'


On Wed, Feb 8, 2017 at 12:23 PM, Pankaj Singh  wrote:

> Hi,
>
> My question is where does SSL client code get the trusted CA certificates
>> from, from Django, Python or the underlying OS?
>
>
> As per official documentation of requests
> 
> library:
>
> By default, Requests bundles a set of root CAs that it trusts, sourced
>> from the Mozilla trust store. However, these are only updated once for each
>> Requests version. This means that if you pin a Requests version your
>> certificates can become extremely out of date.
>>
>
>
> From Requests version 2.4.0 onwards, Requests will attempt to use
>> certificates from certifi if it is present on the system. This allows for
>> users to update their trusted certificates without having to change the
>> code that runs on their system.
>>
>
>
> For the sake of security we recommend upgrading certifi frequently!
>
>
> You can read more about certifi on it's official docs page
> .
>
> What configuration do I need in order for the SSL client to conduct the
>> SSL handshake successfully?
>
>
> You can set REQUESTS_CA_BUNDLE
> 
>  environment variable pointing to .cert file and it will pick it from
> there.
>
> If you have just one `.crt` file which is self signed then you can do
> following
>
> export REQUESTS_CA_BUNDLE='~/Download/bar.example.com.cert'
>
>
> But if you have multiple certificates which are self signed then you can
> put them in a folder and set the folder path in environment variable. In
> case of a folder, make sure to run c_rehash
>  command for
> folder.
>
> mkdir -p /tmp/custom-certs
> cp ~/Download/foo.example.com.cert /tmp/custom-certs
> cp ~/Download/bar.example.com.cert /tmp/custom-certsexport 
> REQUESTS_CA_BUNDLE='/tmp/custom-certs'
>
>
> Relevant source code in requests library: https://github.com/
> kennethreitz/requests/blob/v2.13.0/requests/sessions.py#L658-L662
>
>
> On Tue, Feb 7, 2017 at 10:30 PM, Gang Yang  wrote:
>
>> Hi,
>>
>> I'm pretty new to Django and encountered some client side SSL issue. I'm
>> trying to use django-cas-ng (CAS client) to do CAS authentication and the
>> CAS server is using a self-signed server certificate. After obtaining the
>> service ticket (ST), django-cas-ng tried to verify the ST by calling
>> requests.get(...) and failed with CERTIFICATE_VERIFY_FAILED error.
>> Following some suggestions on the internet, I've tried to modify
>> django-cas-ng's code to call requests.get(..) with verify parameter, such
>> as requests.get(..., verify=False) and requests.get(..., verify="CAS server
>> cert"). Both workarounds worked, but I can't change third-party package
>> code. I also tried to add the CAS server cert to the underlying OS (Windows
>> 2008 and CentOS 6.7), but it did not help.
>>
>> My question is where does SSL client code get the trusted CA certificates
>> from, from Django, Python or the underlying OS? What configuration do I
>> need in order for the SSL client to conduct the SSL handshake successfully?
>>
>> Appreciate any help!
>>
>> Gang
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/f07875b8-f3b8-4bcb-b95f-2d936f5ece34%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
>
> Regards,
> Pankaj Kumar Singh
>
> Mobile: +91 9618754327 <+91%2096187%2054327>
> Skype: psjinx
> Emal: psj...@gmail.com
>



-- 

Regards,
Pankaj Kumar Singh

Mobile: +91 9618754327
Skype: psjinx
Emal: psj...@gmail.com

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPLvEUbyUfrE1nM_GTjENJeGMSAARxw8

Re: No installed app with label 'province'.

2017-02-08 Thread Pankaj Singh
Hi Gerald,

Have you added your new app in 'INSTALLED_APPS' in `settings.py`?

Can you tell more about context of ther error, e.g. this error occurs on
`python manage.py runserver` or when you access a page on django admin?

Also, it would be much easier to find the issue if you can share the
traceback of error.

On Tue, Feb 7, 2017 at 6:19 PM, Gerald Brown  wrote:

> I have just started an app on Ubuntu 16.04 Server using Python 3.5 and
> Django 1.10.5.
>
> When I do "@admin.register(Province)" in my admin.py file I get the error
> that is the subject of this post.
>
> Of course there is NO app with label of 'province' as that is the label of
> a 'Model'.
>
> Why is Django trying to register an app instead of the Model?
>
> Thanks,
>
> Gerald
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5e94b0d3-c6cd-4b24-b323-544d10e97923%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Regards,
Pankaj Kumar Singh

Mobile: +91 9618754327
Skype: psjinx
Emal: psj...@gmail.com

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPLvEUa2-%2BDR8LZ1Zr6BwAvkCG%2BGE39K_ucdiBxXkWONkXbj2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: No installed app with label 'province'.

2017-02-08 Thread Gerald Brown


On Wednesday, February 8, 2017 at 6:08:44 PM UTC+8, Pankaj Singh wrote:
>
> Hi Gerald,
>
> Have you added your new app in 'INSTALLED_APPS' in `settings.py`? No, 
> because "province" is the name of a MODEL, not an app.
>
> Can you tell more about context of ther error, e.g. this error occurs on 
> `python manage.py runserver` or when you access a page on django admin?
>
When I run "runserver" 

>
> Also, it would be much easier to find the issue if you can share the 
> traceback of error.
>
> On Tue, Feb 7, 2017 at 6:19 PM, Gerald Brown  > wrote:
>
>> I have just started an app on Ubuntu 16.04 Server using Python 3.5 and 
>> Django 1.10.5.
>>
>> When I do "@admin.register(Province)" in my admin.py file I get the error 
>> that is the subject of this post.
>>
>> Of course there is NO app with label of 'province' as that is the label 
>> of a 'Model'.
>>
>> Why is Django trying to register an app instead of the Model?
>>
>> Thanks,
>>
>> Gerald
>>
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5e94b0d3-c6cd-4b24-b323-544d10e97923%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> Regards,
> Pankaj Kumar Singh
>
> Mobile: +91 9618754327
> Skype: psjinx
> Emal: psj...@gmail.com 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30903d95-d689-42d7-bb64-d14c5df60aa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


In the admin area Pre-select foreingkey fields for filtered list

2017-02-08 Thread Roberto Russi
In the admin I have a list with a filter on a foreing-key field of model.
In the new record form, when the filter is applied, I wont that foreing-key 
field is pre-compiled with the same value of the filter.

Is there a way?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4507087d-3648-4960-adc2-cd19bf3dfae8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Foreign Key data not showing in formset

2017-02-08 Thread jon
 

I have the following view with an inlineformset for two models: 

   1. Orders, the master / parent model 
   2. LineitemInfo, the detail / child model. 

FormSet


LineFormSet = inlineformset_factory(Orders, LineitemInfo,

can_delete=True,

exclude = ('ordernotes',))

 

The edit order_edit view works fine for the master / parent form, but does 
not display the child records. I can add records to the child form and they 
will save, they do not display however when I select that record (I checked 
the database separately).


def order_edit(request, pk):

order = get_object_or_404(Orders, pk=pk)

if request.method == "POST":

form = OrderForm(request.POST, instance=order)

if form.is_valid():

order = form.save(commit=False)

lineitem_formset = LineFormSet(request.POST, instance=order)

if lineitem_formset.is_valid():

order.save()

lineitem_formset.save()

return redirect('order_list')

else:

form = OrderForm(instance=order)

lineitem_formset = LineFormSet(instance=Orders())

return render(request, "orders/order_edit.html", {"form": form, 
"lineitem_formset": lineitem_formset, })

 

I just get the empty fields on the child / detail form where the data 
should display. What am I missing? TIA

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa49199-da50-4be6-aa82-c28e84596580%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Foreign Key data not showing in formset

2017-02-08 Thread jon
 

As much as I hate to answer my own questions, I was calling instance of an 
empty Order() model rather than the instance of the populated model. So:


lineitem_formset = LineFormSet(instance=Orders())

should have been:


lineitem_formset = LineFormSet(instance=order)


On Wednesday, February 8, 2017 at 8:00:52 AM UTC-5, jon wrote:
>
> I have the following view with an inlineformset for two models: 
>
>1. Orders, the master / parent model 
>2. LineitemInfo, the detail / child model. 
>
> FormSet
>
>
> LineFormSet = inlineformset_factory(Orders, LineitemInfo,
>
> can_delete=True,
>
> exclude = ('ordernotes',))
>
>  
>
> The edit order_edit view works fine for the master / parent form, but does 
> not display the child records. I can add records to the child form and they 
> will save, they do not display however when I select that record (I checked 
> the database separately).
>
>
> def order_edit(request, pk):
>
> order = get_object_or_404(Orders, pk=pk)
>
> if request.method == "POST":
>
> form = OrderForm(request.POST, instance=order)
>
> if form.is_valid():
>
> order = form.save(commit=False)
>
> lineitem_formset = LineFormSet(request.POST, instance=order)
>
> if lineitem_formset.is_valid():
>
> order.save()
>
> lineitem_formset.save()
>
> return redirect('order_list')
>
> else:
>
> form = OrderForm(instance=order)
>
> lineitem_formset = LineFormSet(instance=Orders())
>
> return render(request, "orders/order_edit.html", {"form": form, 
> "lineitem_formset": lineitem_formset, })
>
>  
>
> I just get the empty fields on the child / detail form where the data 
> should display. What am I missing? TIA
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48bdb601-7636-4faa-9af9-b8c10a65c0cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Logs bloated by template variable not found in DEBUG level

2017-02-08 Thread Matthew Pava
I would define avar in the context inside the view function with a value of 
None (or other falsey value).

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Florian Perrodin
Sent: Wednesday, February 8, 2017 3:37 AM
To: Django users
Subject: Logs bloated by template variable not found in DEBUG level

Dear all,

What is the proper way of checking if a variable exists in django?
To my knowledge, the proper way is to use the {% if var %} tag. If this is the 
case, it should not trigger a print in the output (even in the debug log 
level). Hereafter is an example:

# Note: django 1.10.2
from django.template import Context, Template

context = Context({})
template = Template("{% if avar %}bla{% endif %}")

# output
##
DEBUG 2017-02-08 10:19:14,844 base 3090 139658596226880 Exception while 
resolving variable 'avar' in template 'unknown'.
Traceback (most recent call last):
  File "***/python3.4/site-packages/django/template/base.py", line 885, in 
_resolve_lookup
current = current[bit]
  File "***site-packages/django/template/context.py", line 75, in __getitem__
raise KeyError(key)
KeyError: 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 891, in _resolve_lookup
if isinstance(current, BaseContext) and getattr(type(current), bit):
AttributeError: type object 'Context' has no attribute 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 900, in _resolve_lookup
current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'avar'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "***site-packages/django/template/base.py", line 907, in _resolve_lookup
(bit, current))  # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [avar] in 
"[{'True': True, 'False': False, 'None': None}, {}]"
##

I however agree that the following code should generate an debug trace

from django.template import Context, Template

context = Context({})
template = Template("{{ avar }}")


Is there a workaround? Another way to check properly if a variable exists? - 
Note that I want to see other DEBUG messages, so I don't want to change the log 
level

Best regards

Florian

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8cfc93e-3426-48a9-ab77-5154f496f9a2%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7fa22f5bbb0041569e104325bcdedd68%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Logs bloated by template variable not found in DEBUG level

2017-02-08 Thread Derek
If the variable does not exist at all (which is strange, because you should 
be passing in all the variables needed by the template, from the view that 
calls it), then the docs say:

If you use a variable that doesn’t exist, the template system will insert 
the value of the TEMPLATE_STRING_IF_INVALID 

 
setting, which is set to '' (the empty string) by default.
https://docs.djangoproject.com/en/1.7/topics/templates/#variables

so your test could look like:

{% if avar != "" %}



On Wednesday, 8 February 2017 12:08:44 UTC+2, Florian Perrodin wrote:
>
> Dear all,
>
> What is the proper way of checking if a variable exists in django?
> To my knowledge, the proper way is to use the {% if var %} tag. If this is 
> the case, it should not trigger a print in the output (even in the debug 
> log level). Hereafter is an example:
>
> # Note: django 1.10.2
> from django.template import Context, Template
>
> context = Context({})
> template = Template("{% if avar %}bla{% endif %}")
>
> # output
> ##
> DEBUG 2017-02-08 10:19:14,844 base 3090 139658596226880 Exception while 
> resolving variable 'avar' in template 'unknown'.
> Traceback (most recent call last):
>   File "***/python3.4/site-packages/django/template/base.py", line 885, in 
> _resolve_lookup
> current = current[bit]
>   File "***site-packages/django/template/context.py", line 75, in 
> __getitem__
> raise KeyError(key)
> KeyError: 'avar'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "***site-packages/django/template/base.py", line 891, in 
> _resolve_lookup
> if isinstance(current, BaseContext) and getattr(type(current), bit):
> AttributeError: type object 'Context' has no attribute 'avar'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "***site-packages/django/template/base.py", line 900, in 
> _resolve_lookup
> current = current[int(bit)]
> ValueError: invalid literal for int() with base 10: 'avar'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "***site-packages/django/template/base.py", line 907, in 
> _resolve_lookup
> (bit, current))  # missing attribute
> django.template.base.VariableDoesNotExist: Failed lookup for key [avar] in 
> "[{'True': True, 'False': False, 'None': None}, {}]"
> ##
>
> I however agree that the following code should generate an debug trace
>
> from django.template import Context, Template
>
> context = Context({})
> template = Template("{{ avar }}")
>
>
> Is there a workaround? Another way to check properly if a variable exists? 
> - Note that I want to see other DEBUG messages, so I don't want to change 
> the log level
>
> Best regards
>
> Florian
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f9d123d5-0758-4923-9ce8-c4afe80b3c61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Aggregation question

2017-02-08 Thread Viktor Bale
Hi all
No takers, eh? Does this means it also confuses other more experienced 
people, or that it's a silly question? If the aggration function was Avg 
instead of Sum, then it would make perfect sense (the average price per 
page over all books)... but it doesn't, so it doesn't :-) 
Thanks


On Monday, 6 February 2017 13:24:49 UTC+1, Viktor Bale wrote:
>
> This is confusing me. 
>
> In the topic guide on Aggregation (
> https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet), 
> there is an example in the cheat sheet as follows:
>
> # Cost per page>>> from django.db.models import F, FloatField, Sum>>> 
> Book.objects.all().aggregate(...price_per_page=Sum(F('price')/F('pages'), 
> output_field=FloatField())){'price_per_page': 0.4470664529184653}
>
>
> Does this mean:
> i) Calculate the price per page for each book (F('price')/F('pages')) and 
> then aggregate these over all books using the Sum function, or
> ii) Aggregate the price using the Sum function, and also the number of 
> pages using the Sum function, and them divide the former by the latter. 
> ?
>
> Interpretation (i) is what the statement seems to say but this will result 
> in a fairly meaningless number (the sum of cost per page per book, which is 
> dependant on the number of books and doesn't mean much, and is certainly 
> not an average price per page or anything similar).
>
> Interpretation (ii) would make more sense (it calculates the overall price 
> per page over all books), but the fact that the expression 
> (F('price')/F('pages')) is inside the Sum function suggests that this is 
> not what is happening.
>
> Additionally, to aid my understanding, depending on which interpretation 
> is correct, what would the statement be to implement the other 
> interpretation? e.g. is interpretation (i) is what the above statement is 
> doing, how would interpretation (ii) be implmented? Or vice versa
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e84f8af-e2a9-4310-b64e-297fa4ffdea2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Aggregation question

2017-02-08 Thread Tim Graham
As for me, this statement from that page applies, "It’s difficult to intuit 
how the ORM will translate complex querysets into SQL queries so when in 
doubt, inspect the SQL with str(queryset.query) and write plenty of tests."

I'm not good at figuring out at a glance what an aggregation query will do. 
Do some experimentation and you should be able to figure it out yourself.

On Wednesday, February 8, 2017 at 12:41:24 PM UTC-5, Viktor Bale wrote:
>
> Hi all
> No takers, eh? Does this means it also confuses other more experienced 
> people, or that it's a silly question? If the aggration function was Avg 
> instead of Sum, then it would make perfect sense (the average price per 
> page over all books)... but it doesn't, so it doesn't :-) 
> Thanks
>
>
> On Monday, 6 February 2017 13:24:49 UTC+1, Viktor Bale wrote:
>>
>> This is confusing me. 
>>
>> In the topic guide on Aggregation (
>> https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet), 
>> there is an example in the cheat sheet as follows:
>>
>> # Cost per page>>> from django.db.models import F, FloatField, Sum>>> 
>> Book.objects.all().aggregate(...
>> price_per_page=Sum(F('price')/F('pages'), 
>> output_field=FloatField())){'price_per_page': 0.4470664529184653}
>>
>>
>> Does this mean:
>> i) Calculate the price per page for each book (F('price')/F('pages')) and 
>> then aggregate these over all books using the Sum function, or
>> ii) Aggregate the price using the Sum function, and also the number of 
>> pages using the Sum function, and them divide the former by the latter. 
>> ?
>>
>> Interpretation (i) is what the statement seems to say but this will 
>> result in a fairly meaningless number (the sum of cost per page per book, 
>> which is dependant on the number of books and doesn't mean much, and is 
>> certainly not an average price per page or anything similar).
>>
>> Interpretation (ii) would make more sense (it calculates the overall 
>> price per page over all books), but the fact that the expression 
>> (F('price')/F('pages')) is inside the Sum function suggests that this is 
>> not what is happening.
>>
>> Additionally, to aid my understanding, depending on which interpretation 
>> is correct, what would the statement be to implement the other 
>> interpretation? e.g. is interpretation (i) is what the above statement is 
>> doing, how would interpretation (ii) be implmented? Or vice versa
>>
>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42f3ebfc-31fc-4498-bb22-df48a1d21704%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to configure client side SSL trusted CA certificate ?

2017-02-08 Thread Gang Yang
Hi, Pankaj,

Thanks for the reply. The REQUESTS_CA_BUNDLE env var worked as long as I 
start the server manually. But I don't seem to be able to "export" this env 
var into the server daemon process, which is started from /etc/init.d. I'll 
keep digging on the daemon env var.

Gang

On Wednesday, February 8, 2017 at 5:08:44 AM UTC-5, Pankaj Singh wrote:

> Hi,
>
> My question is where does SSL client code get the trusted CA certificates 
>> from, from Django, Python or the underlying OS?
>
>
> As per official documentation of requests 
>  
> library:
>
> By default, Requests bundles a set of root CAs that it trusts, sourced 
>> from the Mozilla trust store. However, these are only updated once for each 
>> Requests version. This means that if you pin a Requests version your 
>> certificates can become extremely out of date.
>>
>  
>
> From Requests version 2.4.0 onwards, Requests will attempt to use 
>> certificates from certifi if it is present on the system. This allows for 
>> users to update their trusted certificates without having to change the 
>> code that runs on their system.
>>
>  
>
> For the sake of security we recommend upgrading certifi frequently!
>
>
> You can read more about certifi on it's official docs page 
> .
>
> What configuration do I need in order for the SSL client to conduct the 
>> SSL handshake successfully?
>
>
> You can set REQUESTS_CA_BUNDLE 
> 
>  environment 
> variable pointing to .cert file and it will pick it from there.
>
> If you have just one `.crt` file which is self signed then you can do 
> following
>
> export REQUESTS_CA_BUNDLE='~/Download/bar.example.com.cert'
>
>
> But if you have multiple certificates which are self signed then you can 
> put them in a folder and set the folder path in environment variable. In 
> case of a folder, make sure to run c_rehash 
>  command for 
> folder.
>
> mkdir -p /tmp/custom-certs
> cp ~/Download/foo.example.com.cert /tmp/custom-certs
> cp ~/Download/bar.example.com.cert /tmp/custom-certsexport 
> REQUESTS_CA_BUNDLE='/tmp/custom-certs'
>
>
> Relevant source code in requests library: 
> https://github.com/kennethreitz/requests/blob/v2.13.0/requests/sessions.py#L658-L662
>
>
> On Tue, Feb 7, 2017 at 10:30 PM, Gang Yang  > wrote:
>
>> Hi,
>>
>> I'm pretty new to Django and encountered some client side SSL issue. I'm 
>> trying to use django-cas-ng (CAS client) to do CAS authentication and the 
>> CAS server is using a self-signed server certificate. After obtaining the 
>> service ticket (ST), django-cas-ng tried to verify the ST by calling 
>> requests.get(...) and failed with CERTIFICATE_VERIFY_FAILED error. 
>> Following some suggestions on the internet, I've tried to modify 
>> django-cas-ng's code to call requests.get(..) with verify parameter, such 
>> as requests.get(..., verify=False) and requests.get(..., verify="CAS server 
>> cert"). Both workarounds worked, but I can't change third-party package 
>> code. I also tried to add the CAS server cert to the underlying OS (Windows 
>> 2008 and CentOS 6.7), but it did not help.
>>
>> My question is where does SSL client code get the trusted CA certificates 
>> from, from Django, Python or the underlying OS? What configuration do I 
>> need in order for the SSL client to conduct the SSL handshake successfully?
>>
>> Appreciate any help!
>>
>> Gang
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/f07875b8-f3b8-4bcb-b95f-2d936f5ece34%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
>
> Regards,
> Pankaj Kumar Singh
>
> Mobile: +91 9618754327
> Skype: psjinx
> Emal: psj...@gmail.com 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3d34bad-244b-4ab4-a893-47a639919f19%40googlegroups.com.
For more options, visit https://groups.go

Re: Aggregation question

2017-02-08 Thread Viktor Bale
Ok, you spurred me on to actually try it out. And the answer is 
interpretation (i) is correct. Which means the example in the cheat sheet 
is somewhat misleading, since it does't calculate price per page, rather 
the sum of prices per page for individual books.

BTW, while playing with that little conundrum, I couldn't work out how to 
display in the shell the SQL query the aggregate() function will execute 
before actually executing it. You can find it after the act using "from 
django.db import connection; print(connection.queries)". And printing 
str(queryset.query) doesn't work like for annotate(), since aggregate() is 
terminal and returns a dict (unlike annotate() which returns another 
queryset). Any ideas?



On Wednesday, 8 February 2017 20:10:59 UTC+1, Tim Graham wrote:
>
> As for me, this statement from that page applies, "It’s difficult to 
> intuit how the ORM will translate complex querysets into SQL queries so 
> when in doubt, inspect the SQL with str(queryset.query) and write plenty 
> of tests."
>
> I'm not good at figuring out at a glance what an aggregation query will 
> do. Do some experimentation and you should be able to figure it out 
> yourself.
>
> On Wednesday, February 8, 2017 at 12:41:24 PM UTC-5, Viktor Bale wrote:
>>
>> Hi all
>> No takers, eh? Does this means it also confuses other more experienced 
>> people, or that it's a silly question? If the aggration function was Avg 
>> instead of Sum, then it would make perfect sense (the average price per 
>> page over all books)... but it doesn't, so it doesn't :-) 
>> Thanks
>>
>>
>> On Monday, 6 February 2017 13:24:49 UTC+1, Viktor Bale wrote:
>>>
>>> This is confusing me. 
>>>
>>> In the topic guide on Aggregation (
>>> https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet), 
>>> there is an example in the cheat sheet as follows:
>>>
>>> # Cost per page>>> from django.db.models import F, FloatField, Sum>>> 
>>> Book.objects.all().aggregate(...
>>> price_per_page=Sum(F('price')/F('pages'), 
>>> output_field=FloatField())){'price_per_page': 0.4470664529184653}
>>>
>>>
>>> Does this mean:
>>> i) Calculate the price per page for each book (F('price')/F('pages')) 
>>> and then aggregate these over all books using the Sum function, or
>>> ii) Aggregate the price using the Sum function, and also the number of 
>>> pages using the Sum function, and them divide the former by the latter. 
>>> ?
>>>
>>> Interpretation (i) is what the statement seems to say but this will 
>>> result in a fairly meaningless number (the sum of cost per page per book, 
>>> which is dependant on the number of books and doesn't mean much, and is 
>>> certainly not an average price per page or anything similar).
>>>
>>> Interpretation (ii) would make more sense (it calculates the overall 
>>> price per page over all books), but the fact that the expression 
>>> (F('price')/F('pages')) is inside the Sum function suggests that this is 
>>> not what is happening.
>>>
>>> Additionally, to aid my understanding, depending on which interpretation 
>>> is correct, what would the statement be to implement the other 
>>> interpretation? e.g. is interpretation (i) is what the above statement is 
>>> doing, how would interpretation (ii) be implmented? Or vice versa
>>>
>>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/18646a22-83b9-4bdb-8efd-8a33a4f0ee96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie question, start server with hostname

2017-02-08 Thread hippohippo
Dear all,

I am a new comer on Django. I was able to to run start server by command as 
below yesterday.

python manage.py runserver http:/hostname:8000 

However today, it submit the error as CommandError: 
"http://te172.24.221.137:8000/"; is not a valid port number or address:port 
pair.

Can anyone give me some hint how to fix this? 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c029b611-898b-4015-b643-e1eaabaa43cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Channels: best way to launch multiple workers

2017-02-08 Thread Charlie DeTar
What's the best way to launch multiple Django channels workers on a 
production server to take advantage of extra cores?

The documentation says 

:

Each server is single-threaded, so it’s recommended you run around one or 
> two per core on each machine; it’s safe to run as many concurrent workers 
> on the same machine as you like, as they don’t open any ports (all they do 
> is talk to the channel backend).


However, `python manage.py help runworker` lists a "--threads" option, 
which seems to imply that a single invocation of runworker can launch 
multiple workers.

Is there a functional difference between `./manage.py runworker --threads 4` 
and launching `./manage.py runworker` process 4 times?

best,
Charlie

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8097b8f7-3f89-49a6-b189-58a0713972ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie question, start server with hostname

2017-02-08 Thread Dylan Reinhold
You don't include the http://
python manage.py runserver hostname:8000 or put the IP address in the
hostname area/

Dylan

On Wed, Feb 8, 2017 at 12:29 PM, hippohippo 
wrote:

> Dear all,
>
> I am a new comer on Django. I was able to to run start server by command
> as below yesterday.
>
> python manage.py runserver http:/hostname:8000
>
> However today, it submit the error as CommandError: "
> http://te172.24.221.137:8000/"; is not a valid port number or address:port
> pair.
>
> Can anyone give me some hint how to fix this? 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/c029b611-898b-4015-b643-e1eaabaa43cc%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHtg44DExi7rq-NkBgjaC6ZMXMc0VFBvNiXuj6GB7R0ynHztqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Channels: best way to launch multiple workers

2017-02-08 Thread Andrew Godwin
The difference is mostly in Python performance - threading in Python tends
to perform worse than using multiple processes, which is why we recommend
using multiple processes in the docs. However, you can save a bit of memory
usage with threading, so you can use that if you want.

I would not, however, recommend running more than 2 - 4 threads per
process, as otherwise you'll likely see performance take a slide due to the
GIL.

Andrew

On Wed, Feb 8, 2017 at 11:53 AM, Charlie DeTar  wrote:

> What's the best way to launch multiple Django channels workers on a
> production server to take advantage of extra cores?
>
> The documentation says
> 
> :
>
> Each server is single-threaded, so it’s recommended you run around one or
>> two per core on each machine; it’s safe to run as many concurrent workers
>> on the same machine as you like, as they don’t open any ports (all they do
>> is talk to the channel backend).
>
>
> However, `python manage.py help runworker` lists a "--threads" option,
> which seems to imply that a single invocation of runworker can launch
> multiple workers.
>
> Is there a functional difference between `./manage.py runworker --threads
> 4` and launching `./manage.py runworker` process 4 times?
>
> best,
> Charlie
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/8097b8f7-3f89-49a6-b189-58a0713972ef%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFwN1uoE7HAdhGdULoSZ7bWzoL_Lu_7gnnoo74m6zFv_POOY9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Aggregation question

2017-02-08 Thread Tim Graham
Please submit a pull request to fix the documentation if you can.

There's an open ticket for a way to get the SQL for a terminal queryset 
method: https://code.djangoproject.com/ticket/18631

On Wednesday, February 8, 2017 at 5:09:25 PM UTC-5, Viktor Bale wrote:
>
> Ok, you spurred me on to actually try it out. And the answer is 
> interpretation (i) is correct. Which means the example in the cheat sheet 
> is somewhat misleading, since it does't calculate price per page, rather 
> the sum of prices per page for individual books.
>
> BTW, while playing with that little conundrum, I couldn't work out how to 
> display in the shell the SQL query the aggregate() function will execute 
> before actually executing it. You can find it after the act using "from 
> django.db import connection; print(connection.queries)". And printing 
> str(queryset.query) doesn't work like for annotate(), since aggregate() is 
> terminal and returns a dict (unlike annotate() which returns another 
> queryset). Any ideas?
>
>
>
> On Wednesday, 8 February 2017 20:10:59 UTC+1, Tim Graham wrote:
>>
>> As for me, this statement from that page applies, "It’s difficult to 
>> intuit how the ORM will translate complex querysets into SQL queries so 
>> when in doubt, inspect the SQL with str(queryset.query) and write plenty 
>> of tests."
>>
>> I'm not good at figuring out at a glance what an aggregation query will 
>> do. Do some experimentation and you should be able to figure it out 
>> yourself.
>>
>> On Wednesday, February 8, 2017 at 12:41:24 PM UTC-5, Viktor Bale wrote:
>>>
>>> Hi all
>>> No takers, eh? Does this means it also confuses other more experienced 
>>> people, or that it's a silly question? If the aggration function was Avg 
>>> instead of Sum, then it would make perfect sense (the average price per 
>>> page over all books)... but it doesn't, so it doesn't :-) 
>>> Thanks
>>>
>>>
>>> On Monday, 6 February 2017 13:24:49 UTC+1, Viktor Bale wrote:

 This is confusing me. 

 In the topic guide on Aggregation (
 https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet),
  
 there is an example in the cheat sheet as follows:

 # Cost per page>>> from django.db.models import F, FloatField, Sum>>> 
 Book.objects.all().aggregate(...
 price_per_page=Sum(F('price')/F('pages'), 
 output_field=FloatField())){'price_per_page': 0.4470664529184653}


 Does this mean:
 i) Calculate the price per page for each book (F('price')/F('pages')) 
 and then aggregate these over all books using the Sum function, or
 ii) Aggregate the price using the Sum function, and also the number of 
 pages using the Sum function, and them divide the former by the latter. 
 ?

 Interpretation (i) is what the statement seems to say but this will 
 result in a fairly meaningless number (the sum of cost per page per book, 
 which is dependant on the number of books and doesn't mean much, and is 
 certainly not an average price per page or anything similar).

 Interpretation (ii) would make more sense (it calculates the overall 
 price per page over all books), but the fact that the expression 
 (F('price')/F('pages')) is inside the Sum function suggests that this is 
 not what is happening.

 Additionally, to aid my understanding, depending on which 
 interpretation is correct, what would the statement be to implement the 
 other interpretation? e.g. is interpretation (i) is what the above 
 statement is doing, how would interpretation (ii) be implmented? Or vice 
 versa

 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30991349-6858-4797-86af-ad9c4cac425e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: file fields

2017-02-08 Thread ايهاب توفيق
hi this backtrace

Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by .wrapper at 0x036B8588>
Traceback (most recent call last):
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\utils\autoreload.py",
 
line 226, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\runserver.py",
 
line 117, in inner_run
self.check_migrations()
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\runserver.py",
 
line 163, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py",
 
line 20, in __init__
self.loader = MigrationLoader(self.connection)
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py",
 
line 49, in __init__
self.build_graph()
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py",
 
line 170, in build_graph
self.load_disk()
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\loader.py",
 
line 105, in load_disk
migration_module = import_module("%s.%s" % (module_name, 
migration_name))
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\importlib\__init__.py",
 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 986, in _gcd_import
  File "", line 969, in _find_and_load
  File "", line 958, in _find_and_load_unlocked
  File "", line 673, in _load_unlocked
  File "", line 665, in exec_module
  File "", line 222, in 
_call_with_frames_removed
  File 
"C:\Users\e.bugaighis\Desktop\ehab\test001\migrations\0007_auto_20161213_1444.py",
 
line 9, in 
class Migration(migrations.Migration):
  File 
"C:\Users\e.bugaighis\Desktop\ehab\test001\migrations\0007_auto_20161213_1444.py",
 
line 19, in Migration
field=models.FileField(blank=True, null=True, 
storage=django.core.files.storage.FileSystemStorage(location=('C:\\Users\\e.bugaighis\\Desktop\\ehab\\media',)),
 
upload_to='/media/'),
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\files\storage.py",
 
line 185, in __init__
self.location = abspathu(self.base_location)
  File 
"C:\Users\e.bugaighis\AppData\Local\Programs\Python\Python35-32\lib\ntpath.py", 
line 535, in abspath
path = _getfullpathname(path)
TypeError: _getfullpathname: illegal type for path parameter

بتاريخ الخميس، 26 يناير، 2017 1:04:28 ص UTC+2، كتب ايهاب توفيق:
>
> I am new in django and to know how to use multiple file field in the same 
> model can any one help me
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/99a9c6a2-2019-4b71-8542-1710bb9ebff7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to configure client side SSL trusted CA certificate ?

2017-02-08 Thread Pankaj Singh
Hi,

You can put export commands in you daemon script. Look at this
stackoverflow answers:
1. http://stackoverflow.com/a/3865077/353550
2. http://stackoverflow.com/a/27718602/353550

You can also find different ways to set environment variables for
supervisord, uwsgi, apache mod_wsgi by Google Search

.

I hope it helps solve your problem.

On Thu, Feb 9, 2017 at 3:07 AM, Gang Yang  wrote:

> Hi, Pankaj,
>
> Thanks for the reply. The REQUESTS_CA_BUNDLE env var worked as long as I
> start the server manually. But I don't seem to be able to "export" this env
> var into the server daemon process, which is started from /etc/init.d. I'll
> keep digging on the daemon env var.
>
> Gang
>
> On Wednesday, February 8, 2017 at 5:08:44 AM UTC-5, Pankaj Singh wrote:
>
>> Hi,
>>
>> My question is where does SSL client code get the trusted CA certificates
>>> from, from Django, Python or the underlying OS?
>>
>>
>> As per official documentation of requests
>> 
>> library:
>>
>> By default, Requests bundles a set of root CAs that it trusts, sourced
>>> from the Mozilla trust store. However, these are only updated once for each
>>> Requests version. This means that if you pin a Requests version your
>>> certificates can become extremely out of date.
>>>
>>
>>
>> From Requests version 2.4.0 onwards, Requests will attempt to use
>>> certificates from certifi if it is present on the system. This allows for
>>> users to update their trusted certificates without having to change the
>>> code that runs on their system.
>>>
>>
>>
>> For the sake of security we recommend upgrading certifi frequently!
>>
>>
>> You can read more about certifi on it's official docs page
>> .
>>
>> What configuration do I need in order for the SSL client to conduct the
>>> SSL handshake successfully?
>>
>>
>> You can set REQUESTS_CA_BUNDLE
>> 
>>  environment variable pointing to .cert file and it will pick it from
>> there.
>>
>> If you have just one `.crt` file which is self signed then you can do
>> following
>>
>> export REQUESTS_CA_BUNDLE='~/Download/bar.example.com.cert'
>>
>>
>> But if you have multiple certificates which are self signed then you can
>> put them in a folder and set the folder path in environment variable. In
>> case of a folder, make sure to run c_rehash
>>  command for
>> folder.
>>
>> mkdir -p /tmp/custom-certs
>> cp ~/Download/foo.example.com.cert /tmp/custom-certs
>> cp ~/Download/bar.example.com.cert /tmp/custom-certsexport 
>> REQUESTS_CA_BUNDLE='/tmp/custom-certs'
>>
>>
>> Relevant source code in requests library: https://github.com/ke
>> nnethreitz/requests/blob/v2.13.0/requests/sessions.py#L658-L662
>>
>>
>> On Tue, Feb 7, 2017 at 10:30 PM, Gang Yang  wrote:
>>
>>> Hi,
>>>
>>> I'm pretty new to Django and encountered some client side SSL issue. I'm
>>> trying to use django-cas-ng (CAS client) to do CAS authentication and the
>>> CAS server is using a self-signed server certificate. After obtaining the
>>> service ticket (ST), django-cas-ng tried to verify the ST by calling
>>> requests.get(...) and failed with CERTIFICATE_VERIFY_FAILED error.
>>> Following some suggestions on the internet, I've tried to modify
>>> django-cas-ng's code to call requests.get(..) with verify parameter, such
>>> as requests.get(..., verify=False) and requests.get(..., verify="CAS server
>>> cert"). Both workarounds worked, but I can't change third-party package
>>> code. I also tried to add the CAS server cert to the underlying OS (Windows
>>> 2008 and CentOS 6.7), but it did not help.
>>>
>>> My question is where does SSL client code get the trusted CA
>>> certificates from, from Django, Python or the underlying OS? What
>>> configuration do I need in order for the SSL client to conduct the SSL
>>> handshake successfully?
>>>
>>> Appreciate any help!
>>>
>>> Gang
>>>
>>> --
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/f07875b8-f3b8-4bcb-b95f-2d936f5ece34%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>>
>> Regards,
>> Pankaj Kumar Singh
>>
>> Mobile: +91 9618754327 <+91%2096187%2054327>