Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread Andréas Kühne
Hi,

I really don't get why you would want to do that? If you are doing only a
"standard" website - you don't want or NEED the extra complexity of running
DRF. It's not that DRF is hard to setup - but for example if you want to
present a list of items - in "standard" django, you create the list and add
it to the context data. In DRF - you need to create the list, serialize it
into json (or xml if you want to go that route), on the frontend you then
need to deserialize the list and present it.

You add a lot of complexity and need to write a lot of frontend code.

Working with "standard" django - you can cache a lot of things in different
places. You can for example cache an entire response with template, or just
cache the database calls and present them in a template. This is not hard
to cache or to setup.

I think I would need to know more about your use case to understand it
better :-)

Regards,

Andréas


Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch :

> I have no need for an externally consumable API, but I am interested in
> using Django-Rest-Framework simply for performance reasons.
>
> I'm led to believe that by decoupling my front and back end and then
> simply consuming the DRF api within views, that I can setup a better
> caching system? Does this make sense? Using DRF from an architectural
> standpoint (with the goal of optimizing caching & performance) despite not
> needing an externally used API? Or am I totally off base and confused? Any
> advice would be much 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8b55ff9a-e915-4546-bf3c-1b20a25e4826%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/CAK4qSCeFqeGT8EbZFbWOGpHKY36D4bwvayLBxGm0YsBBFX6jnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread PASCUAL Eric
Hi,


Using DRF can help when there is a need for decoupling the presentation layer 
from the logic one, for instance if the logic is planned to be used in other 
scenarios that the interactive Web app.


One can argue that structuring the logic as a Python package can do it, but 
this will not work if the deployment involves splitting front-end and logic 
back-end in distinct nodes (f.i. in a Docker multi-container based deployment).


Introducing DRF adds for sure a level of complexity and you'll loose some 
potential caching benefits, but it lets the path opened if ever the above 
mentioned evolution of the application appears in the future. You will not have 
to refactor anything then.


The bottom line is that there is no absolute answer to the question. It depends 
on what can be the plans for the application evolutions in the future.


Regards


Eric


From: django-users@googlegroups.com  on behalf 
of Andréas Kühne 
Sent: Friday, October 26, 2018 9:29:40 AM
To: django-users@googlegroups.com
Subject: Re: Should I use Django-Rest-Framework for performance reasons, 
despite not needing an externally-consumable API?

Hi,

I really don't get why you would want to do that? If you are doing only a 
"standard" website - you don't want or NEED the extra complexity of running 
DRF. It's not that DRF is hard to setup - but for example if you want to 
present a list of items - in "standard" django, you create the list and add it 
to the context data. In DRF - you need to create the list, serialize it into 
json (or xml if you want to go that route), on the frontend you then need to 
deserialize the list and present it.

You add a lot of complexity and need to write a lot of frontend code.

Working with "standard" django - you can cache a lot of things in different 
places. You can for example cache an entire response with template, or just 
cache the database calls and present them in a template. This is not hard to 
cache or to setup.

I think I would need to know more about your use case to understand it better 
:-)

Regards,

Andréas


Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch 
mailto:tyleraly...@gmail.com>>:
I have no need for an externally consumable API, but I am interested in using 
Django-Rest-Framework simply for performance reasons.

I'm led to believe that by decoupling my front and back end and then simply 
consuming the DRF api within views, that I can setup a better caching system? 
Does this make sense? Using DRF from an architectural standpoint (with the goal 
of optimizing caching & performance) despite not needing an externally used 
API? Or am I totally off base and confused? Any advice would be much 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b55ff9a-e915-4546-bf3c-1b20a25e4826%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/CAK4qSCeFqeGT8EbZFbWOGpHKY36D4bwvayLBxGm0YsBBFX6jnw%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/AM6P193MB0421AAC62D90081D00F7FF298CF00%40AM6P193MB0421.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.


Re: New entry tries to use an existing unique id

2018-10-26 Thread Sanjay Bhangar
Hi Michel,

So, a little explanation of why you're facing this issue:

When you create an "auto-increment" field in Postgres, Postgres creates
something called a "sequence" to keep track of the increments. If you were
to `psql` into your database and check the schema of the table, you'll see
the `id` field defined with something like:

id | integer  |   | not null |
nextval('content_id_seq'::regclass)

What this means is that to assign the `id` to an object, it will call the
"nextval" function on the "content_id_seq" sequence, to get the next number
in the sequence. In the normal flow of things, this is not a problem. Every
time you insert a new record into the table, it increments the sequence by
calling the "nextval" operation and populates the id, and the same for the
subsequent row insertion and so on.

Now, the problem arises if you imported data "directly" into the database,
i.e. INSERTed rows including the id, in which case, the database will never
call the "nextval" function internally, and the "sequence" it uses to keep
track of the incrementing ids will never have been updated. I.e. if you
manually insert 3000 rows with ids, the nextval() operation on the sequence
is never called, and hence postgres still thinks the "sequence" is at 1,
and therefore tries to assign the id of, say "2" to the next item, and then
of course fails since there is already an item that you manually inserted
with id 2.

There would be two ways to solve this:

 - 1> When importing the data, leave out the `id` field, and let postgres
populate the id field automatically using the auto-increment nextval()
function so the sequence stays in sync.
 - 2> The other option is to manually reset the sequence to be at whatever
your highest id value is.

The way to manually update the sequence:

For each table where you are facing this problem:

Run `\d` to see the table schema and get the name of the "sequence" ^^ in
my example above, the sequence name is "content_id_seq" - it will generally
follow the format of _id_seq .

Fetch the highest current id with:

SELECT id FROM  ORDER BY id DESC LIMIT 1;

Reset the sequence to the value of the highest id:

SELECT setval('content_id_seq', 4555, true);  # assuming your sequence is
called content_id_seq and the highest id was 4555 .

If doing this individually for each table in the db seems a bit tedious,
you will find various scripts and solutions to automate the process a bit
more by searching for something like "postgres reset sequence" - this is a
fairly common problem and you should find a bunch of material online.

I hope that helps!
-Sanjay


On Fri, Oct 26, 2018 at 6:50 AM Michel Lavoie 
wrote:

> Hi,
>
> I migrated my previous sqlite3 installation to postgresql, following this
> discussion:
> https://groups.google.com/forum/#!msg/django-users/VGG8GTAX4l0/tQUW20HcAwAJ
>
> I'm not facing another weird issue: Whenever I try to create a new item
> (finance.models.Debtor, see
> https://github.com/miek770/huitcent/blob/master/finance/models.py),
> django fails and tells me that primary key (1) is taken. Indeed, the next
> free id is around 3100. The time after that it tries to take id (2), then
> (3), and so on. The error looks like this:
>
> IntegrityError at /finance/2/add_transaction/
>
> duplicate key value violates unique constraint "finance_debtor_pkey"
> DETAIL:  Key (id)=(3) already exists.
>
> Request Method: POST
> Request URL: https://myserver/finance/2/add_transaction/
> Django Version: 2.1.2
> Exception Type: IntegrityError
> Exception Value:
>
> duplicate key value violates unique constraint "finance_debtor_pkey"
> DETAIL:  Key (id)=(3) already exists.
>
> Exception Location: /srv/http/huitcent/lib/python3.5/site-packages/django/
> db/backends/utils.py in _execute, line 85
> Python Executable: /srv/http/huitcent/bin/uwsgi
> Python Version: 3.5.3
> Python Path:
>
> ['.',
>  '',
>  '/srv/http/huitcent/lib/python35.zip',
>  '/srv/http/huitcent/lib/python3.5',
>  '/srv/http/huitcent/lib/python3.5/plat-arm-linux-gnueabihf',
>  '/srv/http/huitcent/lib/python3.5/lib-dynload',
>  '/usr/lib/python3.5',
>  '/usr/lib/python3.5/plat-arm-linux-gnueabihf',
>  '/srv/http/huitcent/lib/python3.5/site-packages']
>
> Server time: jeu, 25 Oct 2018 21:00:14 -0400
>
> As I mentioned before, there are indeed existing entries with these ids.
> My table definition in postgresql (version 10 looks like this:
>
> forum=# \d+ finance_debtor
> Table
> "public.finance_debtor"
>  Column |  Type   | Collation | Nullable |
> Default   | Storage | Stats target | Description
>
> +-+---+--++-+--+-
>  id | integer |   | not null |
> nextval('finance_debtor_id_seq'::regclass) | plain   |  |
>  transaction_id | integer |   | not null |
>   

Re: New entry tries to use an existing unique id

2018-10-26 Thread Michel Lavoie
Wow thank you Sanjay, this is beyond helpful! I'll try the steps you 
suggested; I need the ids to remain the same.

Michel

On Friday, October 26, 2018 at 6:25:09 AM UTC-4, Sanjay Bhangar wrote:
>
> Hi Michel,
>
> So, a little explanation of why you're facing this issue:
>
> When you create an "auto-increment" field in Postgres, Postgres creates 
> something called a "sequence" to keep track of the increments. If you were 
> to `psql` into your database and check the schema of the table, you'll see 
> the `id` field defined with something like:
>
> id | integer  |   | not null | 
> nextval('content_id_seq'::regclass)
>
> What this means is that to assign the `id` to an object, it will call the 
> "nextval" function on the "content_id_seq" sequence, to get the next number 
> in the sequence. In the normal flow of things, this is not a problem. Every 
> time you insert a new record into the table, it increments the sequence by 
> calling the "nextval" operation and populates the id, and the same for the 
> subsequent row insertion and so on.
>
> Now, the problem arises if you imported data "directly" into the database, 
> i.e. INSERTed rows including the id, in which case, the database will never 
> call the "nextval" function internally, and the "sequence" it uses to keep 
> track of the incrementing ids will never have been updated. I.e. if you 
> manually insert 3000 rows with ids, the nextval() operation on the sequence 
> is never called, and hence postgres still thinks the "sequence" is at 1, 
> and therefore tries to assign the id of, say "2" to the next item, and then 
> of course fails since there is already an item that you manually inserted 
> with id 2.
>
> There would be two ways to solve this:
>
>  - 1> When importing the data, leave out the `id` field, and let postgres 
> populate the id field automatically using the auto-increment nextval() 
> function so the sequence stays in sync.
>  - 2> The other option is to manually reset the sequence to be at whatever 
> your highest id value is.
>
> The way to manually update the sequence:
>
> For each table where you are facing this problem:
>
> Run `\d` to see the table schema and get the name of the "sequence" ^^ in 
> my example above, the sequence name is "content_id_seq" - it will generally 
> follow the format of _id_seq .
>
> Fetch the highest current id with:
>
> SELECT id FROM  ORDER BY id DESC LIMIT 1;
>
> Reset the sequence to the value of the highest id:
>
> SELECT setval('content_id_seq', 4555, true);  # assuming your sequence is 
> called content_id_seq and the highest id was 4555 .
>
> If doing this individually for each table in the db seems a bit tedious, 
> you will find various scripts and solutions to automate the process a bit 
> more by searching for something like "postgres reset sequence" - this is a 
> fairly common problem and you should find a bunch of material online.
>
> I hope that helps!
> -Sanjay
>
>
> On Fri, Oct 26, 2018 at 6:50 AM Michel Lavoie  > wrote:
>
>> Hi,
>>
>> I migrated my previous sqlite3 installation to postgresql, following this 
>> discussion: 
>> https://groups.google.com/forum/#!msg/django-users/VGG8GTAX4l0/tQUW20HcAwAJ
>>
>> I'm not facing another weird issue: Whenever I try to create a new item 
>> (finance.models.Debtor, see 
>> https://github.com/miek770/huitcent/blob/master/finance/models.py), 
>> django fails and tells me that primary key (1) is taken. Indeed, the next 
>> free id is around 3100. The time after that it tries to take id (2), then 
>> (3), and so on. The error looks like this:
>>
>> IntegrityError at /finance/2/add_transaction/
>>
>> duplicate key value violates unique constraint "finance_debtor_pkey"
>> DETAIL:  Key (id)=(3) already exists.
>>
>> Request Method: POST
>> Request URL: https://myserver/finance/2/add_transaction/
>> Django Version: 2.1.2
>> Exception Type: IntegrityError
>> Exception Value: 
>>
>> duplicate key value violates unique constraint "finance_debtor_pkey"
>> DETAIL:  Key (id)=(3) already exists.
>>
>> Exception Location: /srv/http/huitcent/lib/python3.5/site-packages/django
>> /db/backends/utils.py in _execute, line 85
>> Python Executable: /srv/http/huitcent/bin/uwsgi
>> Python Version: 3.5.3
>> Python Path: 
>>
>> ['.',
>>  '',
>>  '/srv/http/huitcent/lib/python35.zip',
>>  '/srv/http/huitcent/lib/python3.5',
>>  '/srv/http/huitcent/lib/python3.5/plat-arm-linux-gnueabihf',
>>  '/srv/http/huitcent/lib/python3.5/lib-dynload',
>>  '/usr/lib/python3.5',
>>  '/usr/lib/python3.5/plat-arm-linux-gnueabihf',
>>  '/srv/http/huitcent/lib/python3.5/site-packages']
>>
>> Server time: jeu, 25 Oct 2018 21:00:14 -0400
>>
>> As I mentioned before, there are indeed existing entries with these ids. 
>> My table definition in postgresql (version 10 looks like this:
>>
>> forum=# \d+ finance_debtor
>> Table 
>> "public.finance_debtor"
>>  Column |  Type   | Collation | Nullab

Re: New entry tries to use an existing unique id

2018-10-26 Thread Michel Lavoie
All good now, thanks again. I ended up using this one-liner to do what you 
described:

SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));

Found here: 
https://gist.github.com/henriquemenezes/962829815e8e7875f5f4376133b2f209

Michel

On Friday, October 26, 2018 at 7:10:53 AM UTC-4, Michel Lavoie wrote:
>
> Wow thank you Sanjay, this is beyond helpful! I'll try the steps you 
> suggested; I need the ids to remain the same.
>
> Michel
>
> On Friday, October 26, 2018 at 6:25:09 AM UTC-4, Sanjay Bhangar wrote:
>>
>> Hi Michel,
>>
>> So, a little explanation of why you're facing this issue:
>>
>> When you create an "auto-increment" field in Postgres, Postgres creates 
>> something called a "sequence" to keep track of the increments. If you were 
>> to `psql` into your database and check the schema of the table, you'll see 
>> the `id` field defined with something like:
>>
>> id | integer  |   | not null | 
>> nextval('content_id_seq'::regclass)
>>
>> What this means is that to assign the `id` to an object, it will call the 
>> "nextval" function on the "content_id_seq" sequence, to get the next number 
>> in the sequence. In the normal flow of things, this is not a problem. Every 
>> time you insert a new record into the table, it increments the sequence by 
>> calling the "nextval" operation and populates the id, and the same for the 
>> subsequent row insertion and so on.
>>
>> Now, the problem arises if you imported data "directly" into the 
>> database, i.e. INSERTed rows including the id, in which case, the database 
>> will never call the "nextval" function internally, and the "sequence" it 
>> uses to keep track of the incrementing ids will never have been updated. 
>> I.e. if you manually insert 3000 rows with ids, the nextval() operation on 
>> the sequence is never called, and hence postgres still thinks the 
>> "sequence" is at 1, and therefore tries to assign the id of, say "2" to the 
>> next item, and then of course fails since there is already an item that you 
>> manually inserted with id 2.
>>
>> There would be two ways to solve this:
>>
>>  - 1> When importing the data, leave out the `id` field, and let postgres 
>> populate the id field automatically using the auto-increment nextval() 
>> function so the sequence stays in sync.
>>  - 2> The other option is to manually reset the sequence to be at 
>> whatever your highest id value is.
>>
>> The way to manually update the sequence:
>>
>> For each table where you are facing this problem:
>>
>> Run `\d` to see the table schema and get the name of the "sequence" ^^ in 
>> my example above, the sequence name is "content_id_seq" - it will generally 
>> follow the format of _id_seq .
>>
>> Fetch the highest current id with:
>>
>> SELECT id FROM  ORDER BY id DESC LIMIT 1;
>>
>> Reset the sequence to the value of the highest id:
>>
>> SELECT setval('content_id_seq', 4555, true);  # assuming your sequence is 
>> called content_id_seq and the highest id was 4555 .
>>
>> If doing this individually for each table in the db seems a bit tedious, 
>> you will find various scripts and solutions to automate the process a bit 
>> more by searching for something like "postgres reset sequence" - this is a 
>> fairly common problem and you should find a bunch of material online.
>>
>> I hope that helps!
>> -Sanjay
>>
>>
>> On Fri, Oct 26, 2018 at 6:50 AM Michel Lavoie  
>> wrote:
>>
>>> Hi,
>>>
>>> I migrated my previous sqlite3 installation to postgresql, following 
>>> this discussion: 
>>> https://groups.google.com/forum/#!msg/django-users/VGG8GTAX4l0/tQUW20HcAwAJ
>>>
>>> I'm not facing another weird issue: Whenever I try to create a new item 
>>> (finance.models.Debtor, see 
>>> https://github.com/miek770/huitcent/blob/master/finance/models.py), 
>>> django fails and tells me that primary key (1) is taken. Indeed, the next 
>>> free id is around 3100. The time after that it tries to take id (2), then 
>>> (3), and so on. The error looks like this:
>>>
>>> IntegrityError at /finance/2/add_transaction/
>>>
>>> duplicate key value violates unique constraint "finance_debtor_pkey"
>>> DETAIL:  Key (id)=(3) already exists.
>>>
>>> Request Method: POST
>>> Request URL: https://myserver/finance/2/add_transaction/
>>> Django Version: 2.1.2
>>> Exception Type: IntegrityError
>>> Exception Value: 
>>>
>>> duplicate key value violates unique constraint "finance_debtor_pkey"
>>> DETAIL:  Key (id)=(3) already exists.
>>>
>>> Exception Location: /srv/http/huitcent/lib/python3.5/site-packages/
>>> django/db/backends/utils.py in _execute, line 85
>>> Python Executable: /srv/http/huitcent/bin/uwsgi
>>> Python Version: 3.5.3
>>> Python Path: 
>>>
>>> ['.',
>>>  '',
>>>  '/srv/http/huitcent/lib/python35.zip',
>>>  '/srv/http/huitcent/lib/python3.5',
>>>  '/srv/http/huitcent/lib/python3.5/plat-arm-linux-gnueabihf',
>>>  '/srv/http/huitcent/lib/python3.5/lib-dynload',
>>>  '/usr/lib/python3.5',
>>>  '/usr/lib/python3.5/plat-arm-linux

Experienced django developer is needed.

2018-10-26 Thread deb.dasit2013
Hi, I am experienced Django/Python developer. Kindly provide the details.

-- 
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/de6157b3-f5f0-454a-ab4e-355398e9303a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread Tyler Lynch
Hi Andréas,

Thanks for getting back to me!

I guess adding DRF to my project right now would be a case of 
premature-optimization then. I had a bit of muddied thinking such that I 
thought DRF might help with caching the database queries, but I guess that 
is completely independent of DRF?

Is there no performance reason to adopt DRF?

I'm basically just running a crud app. One thing I was hoping DRF might've 
been able to help me with though is importing/exporting the data as csv's 
as well. I'm not sure though if it's more expedient to just use the csv 
reader. 

Thanks again for the response
On Friday, 26 October 2018 03:30:28 UTC-4, Andréas Kühne wrote:
>
> Hi,
>
> I really don't get why you would want to do that? If you are doing only a 
> "standard" website - you don't want or NEED the extra complexity of running 
> DRF. It's not that DRF is hard to setup - but for example if you want to 
> present a list of items - in "standard" django, you create the list and add 
> it to the context data. In DRF - you need to create the list, serialize it 
> into json (or xml if you want to go that route), on the frontend you then 
> need to deserialize the list and present it.
>
> You add a lot of complexity and need to write a lot of frontend code.
>
> Working with "standard" django - you can cache a lot of things in 
> different places. You can for example cache an entire response with 
> template, or just cache the database calls and present them in a template. 
> This is not hard to cache or to setup. 
>
> I think I would need to know more about your use case to understand it 
> better :-)
>
> Regards,
>
> Andréas
>
>
> Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch  >:
>
>> I have no need for an externally consumable API, but I am interested in 
>> using Django-Rest-Framework simply for performance reasons. 
>>
>> I'm led to believe that by decoupling my front and back end and then 
>> simply consuming the DRF api within views, that I can setup a better 
>> caching system? Does this make sense? Using DRF from an architectural 
>> standpoint (with the goal of optimizing caching & performance) despite not 
>> needing an externally used API? Or am I totally off base and confused? Any 
>> advice would be much 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...@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/8b55ff9a-e915-4546-bf3c-1b20a25e4826%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/7a64fee3-d691-4c68-b29c-cd871c52fbc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread Tyler Lynch
Hi Eric,

Thanks for the response

You mention that adding DRF can actually make you lose some potential 
benefits from caching? Might i ask how that is so? I actually thought it 
was supposed to be the opposite (shows you what I know tho hah)

I guess DRF can be added to the project at any time tho, so there's no need 
to build the project with DRF built-in from beginning. So if I do need it 
down the road, it won't be difficult to add it in. 


On Friday, 26 October 2018 04:28:23 UTC-4, Eric Pascual wrote:
>
> Hi,
>
>
> Using DRF can help when there is a need for decoupling the presentation 
> layer from the logic one, for instance if the logic is planned to be used 
> in other scenarios that the interactive Web app. 
>
>
> One can argue that structuring the logic as a Python package can do 
> it, but this will not work if the deployment involves splitting front-end 
> and logic back-end in distinct nodes (f.i. in a Docker multi-container 
> based deployment). 
>
>
> Introducing DRF adds for sure a level of complexity and you'll loose some 
> potential caching benefits, but it lets the path opened if ever the above 
> mentioned evolution of the application appears in the future. You will not 
> have to refactor anything then.
>
>
> The bottom line is that there is no absolute answer to the question. It 
> depends on what can be the plans for the application evolutions in the 
> future.
>
>
> Regards
>
>
> Eric
> --
> *From:* django...@googlegroups.com  <
> django...@googlegroups.com > on behalf of Andréas Kühne <
> andrea...@hypercode.se >
> *Sent:* Friday, October 26, 2018 9:29:40 AM
> *To:* django...@googlegroups.com 
> *Subject:* Re: Should I use Django-Rest-Framework for performance 
> reasons, despite not needing an externally-consumable API? 
>  
> Hi, 
>
> I really don't get why you would want to do that? If you are doing only a 
> "standard" website - you don't want or NEED the extra complexity of running 
> DRF. It's not that DRF is hard to setup - but for example if you want to 
> present a list of items - in "standard" django, you create the list and add 
> it to the context data. In DRF - you need to create the list, serialize it 
> into json (or xml if you want to go that route), on the frontend you then 
> need to deserialize the list and present it.
>
> You add a lot of complexity and need to write a lot of frontend code.
>
> Working with "standard" django - you can cache a lot of things in 
> different places. You can for example cache an entire response with 
> template, or just cache the database calls and present them in a template. 
> This is not hard to cache or to setup. 
>
> I think I would need to know more about your use case to understand it 
> better :-)
>
> Regards, 
>
> Andréas
>
>
> Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch  >:
>
> I have no need for an externally consumable API, but I am interested in 
> using Django-Rest-Framework simply for performance reasons.  
>
> I'm led to believe that by decoupling my front and back end and then 
> simply consuming the DRF api within views, that I can setup a better 
> caching system? Does this make sense? Using DRF from an architectural 
> standpoint (with the goal of optimizing caching & performance) despite not 
> needing an externally used API? Or am I totally off base and confused? Any 
> advice would be much 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...@googlegroups.com .
> To post to this group, send email to djang...@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/8b55ff9a-e915-4546-bf3c-1b20a25e4826%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 djang...@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/CAK4qSCeFqeGT8EbZFbWOGpHKY36D4bwvayLBxGm0YsBBFX6jnw%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 unsubscr

Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread Andréas Kühne
Hi again,

I don't think there is any performance reason to add DRF. You should
architect your application in a way that the database is the main speed
issue (for example, avoid doing loops in python) - then you can add som
caching to the queries that you know can be cached. That would give you the
best performance regardless if you are running DRF or not :-)

And regardless the added complexity is probably not worth it - as long as
you aren't using it for an external API.

DRF doesn't help importing from / exporting to CSV - it mainly understands
json. I would use some form of CSV export lib - there are a lot of them on
pypi. Or pandas of course!

Regards,

Andréas


Den fre 26 okt. 2018 kl 16:14 skrev Tyler Lynch :

> Hi Andréas,
>
> Thanks for getting back to me!
>
> I guess adding DRF to my project right now would be a case of
> premature-optimization then. I had a bit of muddied thinking such that I
> thought DRF might help with caching the database queries, but I guess that
> is completely independent of DRF?
>
> Is there no performance reason to adopt DRF?
>
> I'm basically just running a crud app. One thing I was hoping DRF might've
> been able to help me with though is importing/exporting the data as csv's
> as well. I'm not sure though if it's more expedient to just use the csv
> reader.
>
> Thanks again for the response
> On Friday, 26 October 2018 03:30:28 UTC-4, Andréas Kühne wrote:
>>
>> Hi,
>>
>> I really don't get why you would want to do that? If you are doing only a
>> "standard" website - you don't want or NEED the extra complexity of running
>> DRF. It's not that DRF is hard to setup - but for example if you want to
>> present a list of items - in "standard" django, you create the list and add
>> it to the context data. In DRF - you need to create the list, serialize it
>> into json (or xml if you want to go that route), on the frontend you then
>> need to deserialize the list and present it.
>>
>> You add a lot of complexity and need to write a lot of frontend code.
>>
>> Working with "standard" django - you can cache a lot of things in
>> different places. You can for example cache an entire response with
>> template, or just cache the database calls and present them in a template.
>> This is not hard to cache or to setup.
>>
>> I think I would need to know more about your use case to understand it
>> better :-)
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch :
>>
>>> I have no need for an externally consumable API, but I am interested in
>>> using Django-Rest-Framework simply for performance reasons.
>>>
>>> I'm led to believe that by decoupling my front and back end and then
>>> simply consuming the DRF api within views, that I can setup a better
>>> caching system? Does this make sense? Using DRF from an architectural
>>> standpoint (with the goal of optimizing caching & performance) despite not
>>> needing an externally used API? Or am I totally off base and confused? Any
>>> advice would be much 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...@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/8b55ff9a-e915-4546-bf3c-1b20a25e4826%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/7a64fee3-d691-4c68-b29c-cd871c52fbc2%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/CAK4qSCc5T_YGQOTa6TF6YQgvgQXvt-AQ5n6M0G

Weird messages in my console

2018-10-26 Thread Mark Phillips
I am building a django 2.0 application, and I have noticed some strange
output in my console when I use runserver. I use logging a lot to follow
what is happening in my code as I write it, so there are a lot of logging
messages in the console. However, these weird messages do not have the same
format as the logging messages.

normal log message:
[2018-10-26 09:16:38] DEBUG [memorabilia.admin.search_metadata:86]
search_metadata END - , Document

weird messages:
date_hierarchy cl=%s created
link=%s ?
link=%s ?created__month=5&created__year=2018
link=%s ?created__month=6&created__year=2018
link=%s ?created__month=10&created__year=2018

>From the flow in the console messages, they come from one of my Admin
classes. I cannot find anything like these messages in that Admin class. At
first, I thought they were some old print statements left over before I
started using logging, but I have grep'ed for any print statements in my
entire code base, and there are not any. They look a little like urls, but
there are not print statements in my urls.py files. I also grep'ed for
parts of these strings and the whole strings, and they are not in any of my
files.

I am stumped on how to track down these strange messages.

Thanks for any help you can provide!

Mark

-- 
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/CAEqej2P2MTKFTLk%2Bs8LSAmPCpAWwb%3DMAzP47Xc9iL_oPyiEvmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't install mysqlclient

2018-10-26 Thread Ing.Daniel Bojorge
For avoid problem, It's better in python start with a Virtual Environment


Dios L@s Bendiga

Saludos,



[image: --]

daniel.bojorge
[image: http://]about.me/daniel.bojorge

 *Curso Django 2.1* 
Mi Blog 
Nicaragua

"Si ustedes permanecen unidos a mí, y si permanecen fieles a mis
enseñanzas, pidan lo que quieran y se les dará.
(Juan 15:7 DHH)
Bendito el varón que se fía en el SEÑOR, y cuya confianza es el SEÑOR.
(Jeremías 17:7 RV2000)



El jue., 25 oct. 2018 a las 7:30, lemme smash () escribió:

> you sure you have mysql server installed?
> also, if you plan to start development, i recommend you to seriously think
> about learning linux. it's a way more fit developers needs
>
> On Thursday, October 25, 2018 at 2:27:43 PM UTC+3, Rabil Abdullahi wrote:
>>
>>
>>
>> I received error message while trying to download mysqlclient using---pip
>> install mysqlclient. Please help me out.
>>
>> Sent from Mail  for
>> Windows 10
>>
>>
>>
> --
> 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/9b0c0310-5d5e-4dab-be5d-3ebb6e185520%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/CAMQeQjY6fgi3EfD7-q%3D12-8JH0awiP5QVdncTZ%3Dpr63seDaZ1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't install mysqlclient

2018-10-26 Thread Swetank Subham Roy
If you are on Linux(debian):
You should first install libmysqlclient-dev using command

$ sudo apt-get install libmysqlclient-dev

Then proceed with installing mysqlclient through pip...

For more information you can follow link:
https://pypi.org/project/mysqlclient/


On Thu 25 Oct, 2018, 6:59 PM lemme smash,  wrote:

> you sure you have mysql server installed?
> also, if you plan to start development, i recommend you to seriously think
> about learning linux. it's a way more fit developers needs
>
> On Thursday, October 25, 2018 at 2:27:43 PM UTC+3, Rabil Abdullahi wrote:
>>
>>
>>
>> I received error message while trying to download mysqlclient using---pip
>> install mysqlclient. Please help me out.
>>
>> Sent from Mail  for
>> Windows 10
>>
>>
>>
> --
> 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/9b0c0310-5d5e-4dab-be5d-3ebb6e185520%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/CADQ%3DdppoGa7gE5-jRHQOwxr26szhDyQB6HYf%2B%2BKcqQV_rQPcsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Channels -- a question about how ProtocolTypeRouter works

2018-10-26 Thread Zhiyu/Drew Li


Hi,

Newbie here. (please bear with me if this a stupid question)

I am going through the tutorial and doc and got this question regarding how 
ProtocolTypeRouter works.
ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a 
key-value pair to it: "http': class AsgiHandler
As doc says ASGI application is created on a per scope basis, I think I vaguely 
understand how the "http" one works. 
Once a http scope comes in, an instance/object of class AsgiHandler is 
initiated, which lasts for the duration of the scope.
So it is one scope leads to one ASGI application/object

But I am confused about this one:
application = ProtocolTypeRouter({
# (http->django views is added by default)
'websocket': AuthMiddlewareStack(
URLRouter(
chat.routing.websocket_urlpatterns
)
),
})
The whole value of this key-value pair 
AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to be 
a object not a class, 
so that means the application already exists before a websocket scope comes in. 
How does this conform to "one scope one application" rule?

Any help would be appreciated.

Thanks
Drew


-- 
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/f6088bd4-457a-4106-b883-332af9a99337%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use Django-Rest-Framework for performance reasons, despite not needing an externally-consumable API?

2018-10-26 Thread PASCUAL Eric
Hi,


You mention that adding DRF can actually make you lose some potential benefits 
from caching?


Django does a lot of job WRT caching data at the ORM level and there is a 
"direct path" from the UI and the ORM. I've the feeling that putting a REST API 
in the middle have chances to defeat some of the involved strategies.


I guess DRF can be added to the project at any time


Yes of course, but the views of the UI layer will have to be reworked. When 
dealing directly with the ORM, they use query sets. When the REST API is added, 
you'll have to deal with serializers instead. The migration will represent some 
work.


So if you think that there are 80% of chances the application will evolve to a 
REST API based architecture in a not too distant future, my advice would be 
introduced it from the begining.


But once again, this is a matter of appreciation.


Best


Eric PASCUAL

Centre Scientifique et Technique du Bâtiment
290 route des Lucioles - BP 209
06904 SOPHIA ANTIPOLIS CEDEX
http://www.cstb.fr


From: django-users@googlegroups.com  on behalf 
of Tyler Lynch 
Sent: Friday, October 26, 2018 4:18:49 PM
To: Django users
Subject: Re: Should I use Django-Rest-Framework for performance reasons, 
despite not needing an externally-consumable API?

Hi Eric,

Thanks for the response

You mention that adding DRF can actually make you lose some potential benefits 
from caching? Might i ask how that is so? I actually thought it was supposed to 
be the opposite (shows you what I know tho hah)

I guess DRF can be added to the project at any time tho, so there's no need to 
build the project with DRF built-in from beginning. So if I do need it down the 
road, it won't be difficult to add it in.


On Friday, 26 October 2018 04:28:23 UTC-4, Eric Pascual wrote:

Hi,


Using DRF can help when there is a need for decoupling the presentation layer 
from the logic one, for instance if the logic is planned to be used in other 
scenarios that the interactive Web app.


One can argue that structuring the logic as a Python package can do it, but 
this will not work if the deployment involves splitting front-end and logic 
back-end in distinct nodes (f.i. in a Docker multi-container based deployment).


Introducing DRF adds for sure a level of complexity and you'll loose some 
potential caching benefits, but it lets the path opened if ever the above 
mentioned evolution of the application appears in the future. You will not have 
to refactor anything then.


The bottom line is that there is no absolute answer to the question. It depends 
on what can be the plans for the application evolutions in the future.


Regards


Eric


From: django...@googlegroups.com  on behalf of 
Andréas Kühne 
Sent: Friday, October 26, 2018 9:29:40 AM
To: django...@googlegroups.com
Subject: Re: Should I use Django-Rest-Framework for performance reasons, 
despite not needing an externally-consumable API?

Hi,

I really don't get why you would want to do that? If you are doing only a 
"standard" website - you don't want or NEED the extra complexity of running 
DRF. It's not that DRF is hard to setup - but for example if you want to 
present a list of items - in "standard" django, you create the list and add it 
to the context data. In DRF - you need to create the list, serialize it into 
json (or xml if you want to go that route), on the frontend you then need to 
deserialize the list and present it.

You add a lot of complexity and need to write a lot of frontend code.

Working with "standard" django - you can cache a lot of things in different 
places. You can for example cache an entire response with template, or just 
cache the database calls and present them in a template. This is not hard to 
cache or to setup.

I think I would need to know more about your use case to understand it better 
:-)

Regards,

Andréas


Den fre 26 okt. 2018 kl 03:44 skrev Tyler Lynch :
I have no need for an externally consumable API, but I am interested in using 
Django-Rest-Framework simply for performance reasons.

I'm led to believe that by decoupling my front and back end and then simply 
consuming the DRF api within views, that I can setup a better caching system? 
Does this make sense? Using DRF from an architectural standpoint (with the goal 
of optimizing caching & performance) despite not needing an externally used 
API? Or am I totally off base and confused? Any advice would be much 
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...@googlegroups.com.
To post to this group, send email to djang...@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/8b55ff9a-e915-4546-bf3c-1b20a25e4826%40google

Re: Channels -- a question about how ProtocolTypeRouter works

2018-10-26 Thread Andrew Godwin
Hi Drew,

The return value is indeed an object, but if you look closely at it you'll
see it defines a __call__ method - meaning that when it's called as an ASGI
application, it then returns a further object to act inside the scope.

Andrew

On Fri, Oct 26, 2018 at 2:55 PM Zhiyu/Drew Li  wrote:

> Hi,
>
> Newbie here. (please bear with me if this a stupid question)
>
> I am going through the tutorial and doc and got this question regarding how 
> ProtocolTypeRouter works.
> ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a 
> key-value pair to it: "http': class AsgiHandler
> As doc says ASGI application is created on a per scope basis, I think I 
> vaguely understand how the "http" one works.
> Once a http scope comes in, an instance/object of class AsgiHandler is 
> initiated, which lasts for the duration of the scope.
> So it is one scope leads to one ASGI application/object
>
> But I am confused about this one:
> application = ProtocolTypeRouter({
> # (http->django views is added by default)
> 'websocket': AuthMiddlewareStack(
> URLRouter(
> chat.routing.websocket_urlpatterns
> )
> ),
> })
> The whole value of this key-value pair 
> AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to 
> be a object not a class,
> so that means the application already exists before a websocket scope comes 
> in. How does this conform to "one scope one application" rule?
>
> Any help would be appreciated.
>
> Thanks
> Drew
>
>
> --
> 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/f6088bd4-457a-4106-b883-332af9a99337%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/CAFwN1urusiZjfH2HSnkaRcuNVUXMgLuLRxs%3DxH9tK%3D35enFDow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels -- a question about how ProtocolTypeRouter works

2018-10-26 Thread Zhiyu (Drew) Li
Thanks!  So that means some objects last across multiple scopes, and they
can create another obj that only lasts for one specific scope?
I am still confused how the different layers of middleware wrap around the
real asgi application -- a obj just lasts for one scope.
I need to go through the code deeper.

Thanks
Drew



On Fri, Oct 26, 2018 at 4:07 PM Andrew Godwin  wrote:

> Hi Drew,
>
> The return value is indeed an object, but if you look closely at it you'll
> see it defines a __call__ method - meaning that when it's called as an ASGI
> application, it then returns a further object to act inside the scope.
>
> Andrew
>
> On Fri, Oct 26, 2018 at 2:55 PM Zhiyu/Drew Li  wrote:
>
>> Hi,
>>
>> Newbie here. (please bear with me if this a stupid question)
>>
>> I am going through the tutorial and doc and got this question regarding how 
>> ProtocolTypeRouter works.
>> ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a 
>> key-value pair to it: "http': class AsgiHandler
>> As doc says ASGI application is created on a per scope basis, I think I 
>> vaguely understand how the "http" one works.
>> Once a http scope comes in, an instance/object of class AsgiHandler is 
>> initiated, which lasts for the duration of the scope.
>> So it is one scope leads to one ASGI application/object
>>
>> But I am confused about this one:
>> application = ProtocolTypeRouter({
>> # (http->django views is added by default)
>> 'websocket': AuthMiddlewareStack(
>> URLRouter(
>> chat.routing.websocket_urlpatterns
>> )
>> ),
>> })
>> The whole value of this key-value pair 
>> AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to 
>> be a object not a class,
>> so that means the application already exists before a websocket scope comes 
>> in. How does this conform to "one scope one application" rule?
>>
>> Any help would be appreciated.
>>
>> Thanks
>> Drew
>>
>>
>> --
>> 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/f6088bd4-457a-4106-b883-332af9a99337%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/CAFwN1urusiZjfH2HSnkaRcuNVUXMgLuLRxs%3DxH9tK%3D35enFDow%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMmsbU%3D0nwz44EzCnMriL2FS-oOL7LyrYOJpp5ocPO3i%3Dj5CFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels -- a question about how ProtocolTypeRouter works

2018-10-26 Thread Andrew Godwin
I would instead think of the object that ends up there as a factory that
makes the final objects that end up per-scope. It's slightly confusing, I
will grant you, but in Python anything can make a new class instance, not
just a class constructor, which is what's happening here.

Andrew

On Fri, Oct 26, 2018 at 3:17 PM Zhiyu (Drew) Li  wrote:

> Thanks!  So that means some objects last across multiple scopes, and they
> can create another obj that only lasts for one specific scope?
> I am still confused how the different layers of middleware wrap around the
> real asgi application -- a obj just lasts for one scope.
> I need to go through the code deeper.
>
> Thanks
> Drew
>
>
>
> On Fri, Oct 26, 2018 at 4:07 PM Andrew Godwin  wrote:
>
>> Hi Drew,
>>
>> The return value is indeed an object, but if you look closely at it
>> you'll see it defines a __call__ method - meaning that when it's called as
>> an ASGI application, it then returns a further object to act inside the
>> scope.
>>
>> Andrew
>>
>> On Fri, Oct 26, 2018 at 2:55 PM Zhiyu/Drew Li  wrote:
>>
>>> Hi,
>>>
>>> Newbie here. (please bear with me if this a stupid question)
>>>
>>> I am going through the tutorial and doc and got this question regarding how 
>>> ProtocolTypeRouter works.
>>> ProtocolTypeRouter.__init__ takes a dict "application_mapping" and append a 
>>> key-value pair to it: "http': class AsgiHandler
>>> As doc says ASGI application is created on a per scope basis, I think I 
>>> vaguely understand how the "http" one works.
>>> Once a http scope comes in, an instance/object of class AsgiHandler is 
>>> initiated, which lasts for the duration of the scope.
>>> So it is one scope leads to one ASGI application/object
>>>
>>> But I am confused about this one:
>>> application = ProtocolTypeRouter({
>>> # (http->django views is added by default)
>>> 'websocket': AuthMiddlewareStack(
>>> URLRouter(
>>> chat.routing.websocket_urlpatterns
>>> )
>>> ),
>>> })
>>> The whole value of this key-value pair 
>>> AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)) seems to 
>>> be a object not a class,
>>> so that means the application already exists before a websocket scope comes 
>>> in. How does this conform to "one scope one application" rule?
>>>
>>> Any help would be appreciated.
>>>
>>> Thanks
>>> Drew
>>>
>>>
>>> --
>>> 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/f6088bd4-457a-4106-b883-332af9a99337%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/CAFwN1urusiZjfH2HSnkaRcuNVUXMgLuLRxs%3DxH9tK%3D35enFDow%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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMmsbU%3D0nwz44EzCnMriL2FS-oOL7LyrYOJpp5ocPO3i%3Dj5CFg%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 https://groups.

html multi button form using in django app

2018-10-26 Thread Xristos Xristoou


down votefavorite 


I have a html form with multi buttons and html tabs processing for every 
button(for example after to push button n01 i take tab 2 with button n02 
after push button n02 i take tab 3 with button n03 where is the final 
button).

my question is to take data from button no1(tab 1) and serve to page 
no2(after push button n01)?

if i keep type="button" then in my view i dont take anything if i change to 
type="submit" then in my view i take results but after push button n01 
refresh my page and start to begin again (dont take to tab 2)

html form :


..


Save 
and continue
   .
   


Save 
and continue

..


Save 
   and continue


django view :

if request.method == 'POST' and 'n01' in request.POST:
   do somethingif request.method == 'POST' and 'n02' in request.POST:
   do something else

-- 
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/b240324e-483b-4fbf-b5b0-fd63902c02bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is assertIs being misused in Tutorial Part 5?

2018-10-26 Thread John Meyer

>
> The reason why assertIs is used instead of assertFalse is that the latter 
> actually tests for falsy values and can sometimes hide bugs.


I understand that if the return type is not pure boolean, it can still 
evaluate to a boolean value.  I tested the following and it possible to do 
the type check explicitly.  

  self.assertIs(future_question.was_published_recently(), bool)
  self.assertEquals(future_question.was_published_recently(), True)

This would be self-documenting in the sense it would help new folks to 
avoid using assertIs as  a general equality check on non-boolean types. 
Would this be okay or would it break with a best practice?


>>
>>  
>> 
>>
>

-- 
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/467ff87a-0e19-4784-868d-549826dcd41a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is assertIs being misused in Tutorial Part 5?

2018-10-26 Thread John Meyer
O, I see what you are saying; False is not really a bool.When 
the function returns a false value, the code returns the following:


AssertionError: False is not 



>>>
>>> 
>>>  
>>> 
>>>
>>

-- 
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/920d98c0-f26b-48e1-8579-19bc87eb9a1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Network analysis tool

2018-10-26 Thread Ryan Nowakowski
It depends on what you want to do. If you want to use websockets then channels 
is a great choice.

If you want to have long running background processes then channels is good for 
most things. Alternatively, Celery is a bit more mature and full-featured.

On October 25, 2018 3:21:58 AM CDT, daniel main  wrote:
>Hello. I want to create a network troubleshooting tool that runs on a
>web
>interface. How efficient is Django channels. Are there alternatives?
>Thank
>you
>
>-- 
>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/CAEEZZ8LZoCfrDgurp7F8KqPveDyydpchHgraF_%3DbLbeVcvXgLQ%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/954250CC-64FD-45CE-B998-A8479F572B2A%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trigger actions independently of url request

2018-10-26 Thread Ryan Nowakowski
Celery is probably what you want. It allows you to run scheduled tasks. 
Alternatively, you can create a custom management command and run that 
periodically some other way: Cron, etc.

On October 22, 2018 3:11:09 PM CDT, Charley Paulus  
wrote:
>Hi Andrew,
>
>Thank you for your answer.
>
>To better clarify my need, here is one use case:
>1) I would like my server (where Django is) to ping a remote address
>(let's 
>say google.com) every 10 minutes, and put the result (communication ok
>or 
>not) in a Django-generated database.
>2) Then I will have a Django view that displays some statistics based
>on 
>this database records. No worries for this point. My question is
>strictly 
>on point 1.
>
>So what I need is my server itself to run code on a regular basis.
>Can I simply start a thread in manage.py, like here: 
>https://eldarion.com/blog/2013/02/14/entry-point-hook-django-projects/
>?
>
>It seems that Celery and AWS Lambda are external tools that can
>remotely 
>call my Django API.
>
>I hope the example helps.
>
>Thanks again.
>
>Best regards,
>Charley
>
>
>On Monday, October 22, 2018 at 1:10:52 PM UTC-4, Andrew Pinkham wrote:
>>
>> On Oct 22, 2018, at 12:08, Charley Paulus > > wrote: 
>> > After reading the Django tutorial, my understanding (I hope I’m
>wrong) 
>> is that the only way to trigger a function of a Django app is when
>someone 
>> on the client side request the url related to that function. 
>>
>> That is correct. A view function/object is only called when a site
>visitor 
>> is routed to that callable by the URL configuration. 
>>
>> > But what if I want the server to run a function indenpendently of a
>url 
>> call, for example: 
>> > - every 10 minutes 
>> > - when a pre-defined combination of variables become true 
>>
>> I'm not clear on your second condition, but you are probably
>interested in 
>> Celery for the first. 
>>
>> http://www.celeryproject.org/ 
>>
>
>
>>
>> Alternatively, some clouds provide the ability to run code on a
>regular 
>> basis. If your Django code is not closely coupled with cron job, you
>could 
>> use AWS Lambda. 
>>
>>
>https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html
>
>>
>> If it is tightly coupled and Celery is too powerful for your needs,
>you 
>> could use an AWS Lambda (or Azure Function, etc) to send a request to
>your 
>> Django API on a regular basis. 
>>
>> Andrew 
>> https://jambonsw.com 
>> https://django-unleashed.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/73e3ded5-45be-4185-95e5-968ef803c75b%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/5FCBFC30-1186-4CDC-973C-9C825CEDC6CC%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trigger actions independently of url request

2018-10-26 Thread Joel
There's nothing that prevents you from doing the necessary imports of your
django model and other required modules in a python script, and then have
it run by cron. Is there?

I've operated python scripts outside of the django application, just to
import certain files into the database, which needs to be done only on the
server side, infrequently. This seems just like this, except it needs to be
done frequently. The linux cron does this very well.

On Tue, 23 Oct, 2018, 1:41 AM Charley Paulus, 
wrote:

> Hi Andrew,
>
> Thank you for your answer.
>
> To better clarify my need, here is one use case:
> 1) I would like my server (where Django is) to ping a remote address
> (let's say google.com) every 10 minutes, and put the result
> (communication ok or not) in a Django-generated database.
> 2) Then I will have a Django view that displays some statistics based on
> this database records. No worries for this point. My question is strictly
> on point 1.
>
> So what I need is my server itself to run code on a regular basis.
> Can I simply start a thread in manage.py, like here:
> https://eldarion.com/blog/2013/02/14/entry-point-hook-django-projects/ ?
>
> It seems that Celery and AWS Lambda are external tools that can remotely
> call my Django API.
>
> I hope the example helps.
>
> Thanks again.
>
> Best regards,
> Charley
>
>
> On Monday, October 22, 2018 at 1:10:52 PM UTC-4, Andrew Pinkham wrote:
>>
>> On Oct 22, 2018, at 12:08, Charley Paulus  wrote:
>> > After reading the Django tutorial, my understanding (I hope I’m wrong)
>> is that the only way to trigger a function of a Django app is when someone
>> on the client side request the url related to that function.
>>
>> That is correct. A view function/object is only called when a site
>> visitor is routed to that callable by the URL configuration.
>>
>> > But what if I want the server to run a function indenpendently of a url
>> call, for example:
>> > - every 10 minutes
>> > - when a pre-defined combination of variables become true
>>
>> I'm not clear on your second condition, but you are probably interested
>> in Celery for the first.
>>
>> http://www.celeryproject.org/
>> 
>>
>> Alternatively, some clouds provide the ability to run code on a regular
>> basis. If your Django code is not closely coupled with cron job, you could
>> use AWS Lambda.
>>
>> https://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html
>>
>> If it is tightly coupled and Celery is too powerful for your needs, you
>> could use an AWS Lambda (or Azure Function, etc) to send a request to your
>> Django API on a regular basis.
>>
>> Andrew
>> https://jambonsw.com
>> https://django-unleashed.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/73e3ded5-45be-4185-95e5-968ef803c75b%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/CAA%3Diw_9SAgunm1_0qSTi8mqAGwmS2pJNNwRm2HO4kYTUHGA7zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Network analysis tool

2018-10-26 Thread daniel main
Thanks for the reply. I want to create an interface that will visualize the
TCP and UDP dump data and also a section showing the upload and download
speeds

On Oct 27, 2018 04:52, "Ryan Nowakowski"  wrote:

> It depends on what you want to do. If you want to use websockets then
> channels is a great choice.
>
> If you want to have long running background processes then channels is
> good for most things. Alternatively, Celery is a bit more mature and
> full-featured.
>
> On October 25, 2018 3:21:58 AM CDT, daniel main 
> wrote:
>>
>> Hello. I want to create a network troubleshooting tool that runs on a web
>> interface. How efficient is Django channels. Are there alternatives? Thank
>> you
>>
>> --
> 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/954250CC-64FD-45CE-B998-A8479F572B2A%40fattuba.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/CAEEZZ8%2B75ZNM_QqsYWiWgz3i_K_mPsfy-oVVORj4eouyJTsgmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


NOT ABLE TO INSTALL REQUIREMENT FILES

2018-10-26 Thread Dennis Alabi
I'm trying to clone an app into virtual environment but i keep getting the 
error below. Please what should i do about this "  error: command 'cl.exe' 
failed: No such file or directory"

Part of the code is shown below.





rs c:\users\user\envs\ososo\include\site\python3.6\rjsmin:
running install
running build
running build_py
creating build
creating build\lib.win32-3.6
copying .\rjsmin.py -> build\lib.win32-3.6
running build_ext
building '_rjsmin' extension
creating build\temp.win32-3.6
creating build\temp.win32-3.6\Release
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DEXT_MODULE=_rjsmin 
-UEXT_PACKAGE -I_setup/include 
-Ic:\users\user\appdata\local\programs\python\python36-32\include 
-Ic:\users\user\appdata\local\programs\python\python36-32\include 
"-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Include" 
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" 
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" 
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" 
"-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" 
"-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um" /Tcrjsmin.c 
/Fobuild\temp.win32-3.6\Release\rjsmin.obj
error: command 'cl.exe' failed: No such file or directory

-- 
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/f6d67558-a2f5-4b11-b658-2b9f32b2faa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.