Re: how to prevent Django do auto capitalize static text in templates

2021-05-18 Thread Liu Zheng
Checking CSS is the right way to go. To verify, simply comment out all css
styles (internal or external ones) and strip off the classes from these few
lines. You shouldn’t have capitalisation problem any more

On Tue, 18 May 2021 at 9:23 PM, Samuel Nogueira 
wrote:

> I am using bootstrap, so my CSS shouldn't go wrong
>
>
> Em ter., 18 de mai. de 2021 às 10:04, 712189512 <
> gabrielstonede...@gmail.com> escreveu:
>
>> It’s not django that’s doing that,have you checked your css?
>>
>> On Tue, 18 May 2021 at 12:56 David Tobrise  wrote:
>>
>>> What happens if you try outputting the units from dynamically instead of
>>> hard-coding it?
>>>
>>> *Best Regards,*
>>> *David O. T.*
>>>
>>>
>>>
>>>
>>> On Tue, May 18, 2021 at 1:07 PM samuel nogueira bacelar <
>>> hu3mule...@gmail.com> wrote:
>>>
 Hi guys!

 I have something that appears to be a simple problem but I didn’t find
 anything useful anywhere. My problem is that my text in a template next to
 a Django tag keeps auto capitalizing but I don’t want this to happen.



 In the image above you can see that m³/ano and m² is not capitalized at
 all. But bellow my text keeps capitalizing.





 How can I prevent that to happen?



 --
 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 view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/55BF1950-88D1-47E5-9654-18039E00E75E%40hxcore.ol
 
 .

>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAKeCWo_m7UqF-HLXr0Y%3DgzO9Puu%2BKCuA_mKF86-TPg3sv8QjXw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> Gabrielstone
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAL-5MpXOhhj-ktjZrZqYmUbF6U933j9MFJr-cCmf67JcMxxO0A%40mail.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOJT-cDo50jVF-QCZDWaoTTNQ4yrk3BnC2sszsp6a%3DgyhGmcOg%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf97JKCnJshVEoHN%2Bi-OMB-x3-njaH%3DOZHVyqPtgbGPhmg%40mail.gmail.com.


Re: Is it possible to use REST API on Django template ?

2020-11-30 Thread Liu Zheng
Hi,

Guys earlier have provided useful links for consuming APIs. Just want to
emphasize some concepts between server-side and client-side codes.
A django template is rendered into a page on the *server side*. That means,
the server does the work and prepares the html content before sending it to
the browser. In theory, you can call APIs when rendering the templates on
the server side, but it's almost never a good idea. APIs are designed to be
consumed by *clients*. The django templates should contain the relevant
javascripts (using ajax). These javascripts are not executed when the
server renders the templates. They are sent as they are to the client, and
are executed automatically by the browser. If the javascript calls API, the
browser will come back to your server (this time, to the rest api
endpoints, instead of the template rendering endpoints) and consume your
API.

Hope it helps.

Best
Zheng

On Mon, Nov 30, 2020 at 1:30 AM sree e  wrote:

>
> Hi
> find this link
> https://github.com/sumasreeeduru/Textyfi
> And go through "api" app , where you will find adding the api in easy way.
> On Sunday, November 29, 2020 at 12:36:44 PM UTC+5:30 bharath...@gmail.com
> wrote:
>
>> Hi
>> Use JavaScript or jQuery to call APIs in frontend of Django template.
>> You can use fetch API using vanilla JavaScript.
>> You can perform all CRUD operations.
>> All the best 
>>
>> On Sun, 29 Nov 2020, 11:57 am Aman Modi,  wrote:
>>
>>> I know how to create API but i just want to know how to use in Django
>>> template.
>>>
>>> On Wednesday, November 25, 2020 at 8:07:47 PM UTC+5:30
>>> omkar...@gmail.com wrote:
>>>
 Creating REST API in Django is similar to any app on Django. All you
 need to do is, install the djangorestframework library, and serialize your
 models.

 YT video 
 https://youtu.be/TmsD8QExZ84
 On Wed, Nov 25, 2020, 7:48 PM Aman Modi  wrote:

>
>
> Hello Django lovers.
>
> I want to use REST API  on the Django template but I have no idea how
> can I do that.
> I want to use the same API on the android app and the Django template.
>
> Any suggestion.
>

> Thanks and regard
> Aman Modi
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/99c6d921-9ea7-4f3b-9d69-03b06fbbd5d8n%40googlegroups.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...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/9219ddfb-a07d-40b4-9e64-8324520043f7n%40googlegroups.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5bea74b3-647b-45ca-9623-4951b08c911fn%40googlegroups.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf8_75diWytaSsDK7tcDnqSsPizAXq7BzQ7nM-LonrFhMA%40mail.gmail.com.


Re: deploying a django project

2020-09-07 Thread Liu Zheng
@Omkar Parab: Lol. Exactly. When I saw the question, this video was the
first in my mind. I clicked in to share the link, but you have shared it.

Cheers!

On Tue, Sep 8, 2020 at 5:14 AM Omkar Parab  wrote:

> Follow this video.
> https://youtu.be/6DI_7Zja8Zc
>
> On Tue, Sep 8, 2020, 2:36 AM programmer 262 
> wrote:
>
>> hy guys i start learning django  and i build a ecommerce website as
>> myfirst project and i don't know how to deploy it in heroku
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/2742aa36-8108-4810-9990-3a78866171can%40googlegroups.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJY8mfzxQxh_ef9MtSzRq2VeJ_Rsyfqa9COj%2BYidNLTyxf2EWg%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf9NV3adydf2US1veQO97gEywQ4MfvEef4mk-abY7j_c6A%40mail.gmail.com.


Re: type error

2020-08-18 Thread Liu Zheng
hi,

What’s the type and value of that variable “value”? It would be helpful to
print out value and type(value) right in front of this line where error
occurs.

Best
Zheng

On Tue, 18 Aug 2020 at 9:21 PM, Rostislav Kornatsky <
info.send.o...@gmail.com> wrote:

> Hi, my name is Rostislav and I'm learning Django too, We could collaborate
> and learn it together:)
>
> пт, 14 авг. 2020 г. в 21:50, Peter Kirieny :
>
>> hello, can somebody help with this please
>>
>> match = datetime_re.match(value)
>> TypeError: expected string or bytes-like object
>>
>> I've made migrations but now i can't migrate, it brings the above error
>> instead
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>>
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAL8t8epXffzY6L6ox8whRQuf16n1bGOuQ9pGnHEWPt_XQBahqg%40mail.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPe0rWvVEVE%2B-3vaSq5VCWmQFBY4T5FTn2tLVs_hKD%3DfHv6CaA%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf9_TLkj8%3D6qD9%2BNYU3r1YnepGc-isMai2G9D-PLj4Lqfw%40mail.gmail.com.


Re: Security issue in django.db.models

2020-08-09 Thread Liu Zheng
All the previous answers are great to explain the reason. Just want to add:
if you do not desire empty string in form and in shell, you probably need
to add a min_length validation condition

On Sun, Aug 9, 2020 at 12:42 PM Stephen J. Butler 
wrote:

> If you look at the documentation for 'blank' it says:
>
> """
> Note that this is different than null. null is purely database-related,
> whereas blank is validation-related. If a field has blank=True, *form
> validation* will allow entry of an empty value. If a field has
> blank=False, the field will be required.
> """
>
> So that is only caught when doing form validation, not when doing model
> validation.
>
>
> On Fri, Aug 7, 2020 at 6:46 AM Juan D.  wrote:
>
>> I've created a model with null and blank set to False in robot_name:
>>
>> class Robot(models.Model):
>> robot_name = models.CharField(max_length=200, null=False, blank=False)
>> version = models.CharField(max_length=20, blank=True, null=True)
>>
>> class Meta:
>> unique_together = ('robot_name', 'version',)
>>
>> On the admin website everything works perfectly and I am not allowed to
>> create a robot without a name. However, on the shell:
>>
>> Robot.objects.create(version="test_version")
>>
>> doesn't raise any Exception.
>>
>> What could it be?
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/4ff1570e-70a2-495c-82e3-f20d760992d2n%40googlegroups.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAD4ANxV3r35zB70M4D6s_35PuxUeYay5JQUFuPOfJAA6vovBxQ%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf9ve5jj3kVBzXqAm9J86Yq0U57B_iLRnL7SnsTtdGcvfA%40mail.gmail.com.


Re: Django jinja queryset filter lenth

2020-08-09 Thread Liu Zheng
Hi,

Not sure it's a good idea to do database query inside the template.
Templates are capable of running some logics but for a heavy-lifting job
like database query, it should be a good practice to do it in the view, and
only pass the results to the template.

On Sun, Aug 9, 2020 at 4:30 AM Agoua David  wrote:

> As Django template engine do not support the parenthèses you Can try to
> make a custom filter
>
> Le sam. 8 août 2020 à 20:27, Agoua David  a écrit :
>
>> You Can try to use .count instead
>>
>> Le sam. 8 août 2020 à 17:56, N'BE SORO  a écrit :
>>
>>> Good evening please
>>>
>>> Can you help me?
>>>
>>> I want to display the number of items with a filter.
>>> Example:
>>> this call returns 4 elements
>>> {{ item.class.classecours.all|length}}
>>>
>>> at the .all level
>>> make an item.class.classecours.filter(status==True)|length
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAOtSHp_wH9Xy-sf9t%2BMdtWB-bnRX680R9iJwZAnyZXh%3DxV%3De%3Dg%40mail.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAByCr6iR%2BKojR-csC3Rv5zqYd7mUG4%2B%2BnvEcM_ebZmM%2BceRmsw%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf-MmY%2BnNLEZHEyyPGE46%2Bv9s52Vvic2AfhdDGJ36Jwr4g%40mail.gmail.com.


Re: Import csv file on django view

2020-07-24 Thread Liu Zheng
Yes. You are right. Pandas' default behavior is as following:

encoding = sys.getsystemencoding() or "utf-8"

I tried to open a simple csv encoded into "utf16-LE" (popular on windows),
and got the following error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0:
invalid start byte

On Sat, Jul 25, 2020 at 5:13 AM Ronaldo Mata 
wrote:

> Hi Pandas require knows the encoding and delimiter previously when you use
> pd.read_csv(filepath, encoding=" ", delimiter=" ") I think that is the same
> 樂
>
> El vie., 24 de julio de 2020 3:42 p. m., Jani Tiainen 
> escribió:
>
>> Hi,
>>
>> I highly can recommend to use pandas to read csv. It does pretty good job
>> to guess a lot of things without extra config.
>>
>> Of course it's one more extra dependency.
>>
>>
>> pe 24. heinäk. 2020 klo 17.09 Ronaldo Mata 
>> kirjoitti:
>>
>>> Yes, I will try it. Anythin I will let you know
>>>
>>> El mié., 22 de julio de 2020 12:24 p. m., Liu Zheng <
>>> firstday2...@gmail.com> escribió:
>>>
>>>> Hi,
>>>>
>>>> Are you sure that the file used for detection is the same as the file
>>>> opened and decoded and gave you incorrect information?
>>>>
>>>> By the way, ascii is a proper subset of utf-8. If chardet said it
>>>> ascii, decoding it using utf-8 should always work.
>>>>
>>>> If your file contains non-ascii UTF-8 bytes, maybe it’s a bug in
>>>> chardet? You can try it directly, without mixing it with django’s requests
>>>> first. Make sure you can detect and decode the file locally in a test
>>>> program. Then put it into the app.
>>>>
>>>> If you share the file, i’m also glad to help you try it.
>>>>
>>>> On Thu, 23 Jul 2020 at 12:04 AM, Ronaldo Mata 
>>>> wrote:
>>>>
>>>>> Hi Kovy, this is not solved. Liu Zheng but using
>>>>> chardet(request.FILES['file'].read()) return encoding "ascii" is not
>>>>> correct, I've uploaded a file using utf-7 as encoding for example and the
>>>>> result is wrog. and then I tried
>>>>> request.FILES['file'].read().decode('ascii') and not work return bad data.
>>>>> Example for @ string return "+AEA-" string.
>>>>>
>>>>> El mié., 22 jul. 2020 a las 11:16, Kovy Jacob ()
>>>>> escribió:
>>>>>
>>>>>> I’m confused. I don’t know if I can help.
>>>>>>
>>>>>> On Jul 22, 2020, at 11:11 AM, Liu Zheng 
>>>>>> wrote:
>>>>>>
>>>>>> Hi, glad you solved the problem. Yes, both the request.FILES[‘file’]
>>>>>> and the chardet file handler are binary handlers. Binary handler presents
>>>>>> the raw data. chardet takes a sequence or raw data and then detect the
>>>>>> encoding format. With its prediction, if you want to open that puece of
>>>>>> data in text mode, you can use the .decode() method of
>>>>>> bytes object to get a python string.
>>>>>>
>>>>>> On Wed, 22 Jul 2020 at 11:04 PM, Kovy Jacob 
>>>>>> wrote:
>>>>>>
>>>>>>> That’s probably not the proper answer, but that’s the best I can do.
>>>>>>> Sorry :-(
>>>>>>>
>>>>>>>
>>>>>>> On Jul 22, 2020, at 10:46 AM, Ronaldo Mata 
>>>>>>> wrote:
>>>>>>>
>>>>>>> Yes, the problem here is that the files will be loaded by the user,
>>>>>>> so I don't know what delimiter I will receive. This is not a base 
>>>>>>> command
>>>>>>> that I am using, it is the logic that I want to incorporate in a view
>>>>>>>
>>>>>>> El mié., 22 jul. 2020 a las 10:43, Kovy Jacob ()
>>>>>>> escribió:
>>>>>>>
>>>>>>>> Ah, so is the problem that you don’t always know what the delimiter
>>>>>>>> is when you read it? If yes, what is the use case for this? You might 
>>>>>>>> not
>>>>>>>> need a universal solution, maybe just put all the info into a csv 
>>>>>>>> yourself,
>>>>>>>> manually.
>>>>>>>>
>>>>>>>> On Jul 22, 2020, at 10:39 AM, Ronaldo Mata 
>

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
Hi,

Are you sure that the file used for detection is the same as the file
opened and decoded and gave you incorrect information?

By the way, ascii is a proper subset of utf-8. If chardet said it ascii,
decoding it using utf-8 should always work.

If your file contains non-ascii UTF-8 bytes, maybe it’s a bug in chardet?
You can try it directly, without mixing it with django’s requests first.
Make sure you can detect and decode the file locally in a test program.
Then put it into the app.

If you share the file, i’m also glad to help you try it.

On Thu, 23 Jul 2020 at 12:04 AM, Ronaldo Mata 
wrote:

> Hi Kovy, this is not solved. Liu Zheng but using
> chardet(request.FILES['file'].read()) return encoding "ascii" is not
> correct, I've uploaded a file using utf-7 as encoding for example and the
> result is wrog. and then I tried
> request.FILES['file'].read().decode('ascii') and not work return bad data.
> Example for @ string return "+AEA-" string.
>
> El mié., 22 jul. 2020 a las 11:16, Kovy Jacob ()
> escribió:
>
>> I’m confused. I don’t know if I can help.
>>
>> On Jul 22, 2020, at 11:11 AM, Liu Zheng  wrote:
>>
>> Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and
>> the chardet file handler are binary handlers. Binary handler presents the
>> raw data. chardet takes a sequence or raw data and then detect the encoding
>> format. With its prediction, if you want to open that puece of data in text
>> mode, you can use the .decode() method of bytes object to
>> get a python string.
>>
>> On Wed, 22 Jul 2020 at 11:04 PM, Kovy Jacob  wrote:
>>
>>> That’s probably not the proper answer, but that’s the best I can do.
>>> Sorry :-(
>>>
>>>
>>> On Jul 22, 2020, at 10:46 AM, Ronaldo Mata 
>>> wrote:
>>>
>>> Yes, the problem here is that the files will be loaded by the user, so I
>>> don't know what delimiter I will receive. This is not a base command that I
>>> am using, it is the logic that I want to incorporate in a view
>>>
>>> El mié., 22 jul. 2020 a las 10:43, Kovy Jacob ()
>>> escribió:
>>>
>>>> Ah, so is the problem that you don’t always know what the delimiter is
>>>> when you read it? If yes, what is the use case for this? You might not need
>>>> a universal solution, maybe just put all the info into a csv yourself,
>>>> manually.
>>>>
>>>> On Jul 22, 2020, at 10:39 AM, Ronaldo Mata 
>>>> wrote:
>>>>
>>>> Hi Kovy, I'm using csv module, but I need to handle the delimiters of
>>>> the files, sometimes you come separated by "," others by ";" and rarely by
>>>> "|"
>>>>
>>>> El mié., 22 jul. 2020 a las 10:28, Kovy Jacob ()
>>>> escribió:
>>>>
>>>>> Could you just use the standard python csv module?
>>>>>
>>>>> On Jul 22, 2020, at 10:25 AM, Ronaldo Mata 
>>>>> wrote:
>>>>>
>>>>> Hi Liu thank for your answer.
>>>>>
>>>>> This has been a headache, I am trying to read the file using
>>>>> csv.DictReader initially i had an error trying to get the dict keys when
>>>>> iterating by rows, and i thought it could be encoding (for this reason i
>>>>> wanted to prepare the view to use the correct encoding). for that reason I
>>>>> asked my question.
>>>>>
>>>>> 1) your first approach doesn't work, if i send utf-8 file, chardet
>>>>> returns ascii as encoding. it seems request.FILES ['file']. read () 
>>>>> returns
>>>>> a binary with that encoding.
>>>>>
>>>>> 2) In the end I realized that the problem was the delimiter of the csv
>>>>> but predicting it is another problem.
>>>>>
>>>>> Anyway, it was a task that I had to do and that was my limitation. I
>>>>> think there must be a library that does all this, uploading a csv file is
>>>>> common practice in many web apps.
>>>>>
>>>>> El mar., 21 jul. 2020 a las 13:47, Liu Zheng ()
>>>>> escribió:
>>>>>
>>>>>> Hi. First of all, I think it's impossible to perfectly detect
>>>>>> encoding without further information. See the answer in this SO post:
>>>>>> https://stackoverflow.com/questions/436220/how-to-determine-the-encoding-of-text
>>>>>>  There
>>>>>> are many packages and tools to

Re: How to trace circular import error Django never solved!! Please sort this out.

2020-07-22 Thread Liu Zheng
Hi,

Probably not enough to look at urls.py files only. My guess: Do you use
‘reverse’ function anywhere in covid app? If so, here’s a circular import:

urls.py imports covid urls -> covid urls import covid views -> one covid
view uses reverse -> reverse import urls.py of the project (to look up the
url with the end point name).

A quick fix will be using lazy_reverse instead of reverse.

On Wed, 22 Jul 2020 at 10:22 PM, sandeep kumar 
wrote:

> I have faced this issue atleast 100 times..:)
>
> Her are the steps (sorry, I could not find a better way):
>
> 1. comment urls in urls.py (inside individual app)
> 2. check if you still have issue
> 2a. if you do not have issue, then you probably have not defined views for
> some of the urls
> 2b. if you still see the error, comment 'impot views' statement.
> 3a. if the issue is gone after commenting 'import views' then check
> views.py file, it must have some typos (e.g., misalignment, accidental
> copying of some special character etc.)
> 3b. if the issue is not gone even after commenting 'import views', let me
> know. I am not sure I have reached that stage ever..:)
>
> Hope this helps.
>
> Thanks,
> Sandeep
>
> --
> *Dr. Sandeep Kumar,*
> Postdoctoral Researcher,
> Lunenfeld Tanenbaum Research Institute,
> Mount Sinai Hospital,
> 600 University Ave,
> 
> Toronto, Ontario
> 
> Canada
> 
> http://individual.utoronto.ca/sandeepkumar/
>
>
> On Wed, Jul 22, 2020 at 10:12 AM Chaitanya Sai 
> wrote:
>
>> Hello Django users,
>> Is there not even single person who can solve this issue??
>>
>>
>> On Tue, Jul 21, 2020 at 8:09 PM Sai  wrote:
>>
>>> I am working Django rest framework api project, where I had multiple
>>> apps in the project. I got a circular import error when I am adding the app
>>> URLs to the main URLs. I Tried everything checked spellings, checked app
>>> structure but no use. Its been really frustrating with issue..please help
>>> to solve the problem. The app is working fine when I take off newly added
>>> line `path("covid/", include("Covid.urls")),`
>>>
>>> I am using python3.6, django 3.0.4 and django-rest-framework 3.11.0
>>>
>>> Here is project
>>> **urls.py**
>>>
>>>
>>> from django.contrib import admin
>>> from django.conf.urls import url
>>> from django.urls import path, include
>>> from rest_framework_swagger.views import get_swagger_view
>>>
>>> schema_view = get_swagger_view(title='TmmrwInc API Documentation')
>>>
>>> urlpatterns = [
>>> path('admin/', admin.site.urls),
>>> # path('', include('django.contrib.auth.urls')),
>>> # path('rest_auth/', include('rest_auth.urls')),
>>> path('api/password_reset/',
>>> include('django_rest_passwordreset.urls',
>>> namespace='password_reset')),
>>> # url(r'^invitations/', include('invitations.urls',
>>> namespace='invitations')),
>>> path('', include('rest_invitations.urls')),
>>> path("", include("UserAuth.urls")),
>>> path("doctors/", include("Administration.urls")),
>>> path("appointments/", include("Appointments.urls")),
>>> path("messaging/", include("messaging.urls")),
>>> path("meet/", include("meet.urls")),
>>> path("api_documentation/", schema_view),
>>> path("covid/", include("Covid.urls")),
>>> ]
>>>
>>> This is app **urls.py** file
>>>
>>> from django.urls import path
>>> from . import views
>>>
>>> app_name = 'Covid'
>>>
>>> urlpatterns = [
>>> path('event/', views.EventBookingView.as_view()),
>>> ]
>>>
>>> **settings.py** installed apps
>>>
>>> ALLOWED_HOSTS = ['*']
>>>
>>>
>>> # Application definition
>>>
>>> INSTALLED_APPS = [
>>> "django.contrib.admin",
>>> "django.contrib.auth",
>>> "django.contrib.sites",
>>> "django.contrib.contenttypes",
>>> "django.contrib.sessions",
>>> "django.contrib.messages",
>>> "django.contrib.staticfiles",
>>> "UserAuth",
>>> "rest_framework",
>>> "corsheaders",
>>> 'rest_framework.authtoken',
>>> 'rest_auth',
>>> 'Appointments',
>>> 'messaging',
>>> 'Administration',
>>> 'channels',
>>> 'invitations',
>>> 'rest_invitations',
>>> 'django_rest_passwordreset',
>>> 'django_celery_beat',
>>> 'meet',
>>> 'rest_framework_swagger',
>>>  'Covid',
>>>
>>> ]
>>>
>>> This is a project structure
>>>
>>> [Project Structure][1]
>>>
>>>
>>>   [1]: https://i.stack.imgur.com/E8qro.jpg
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe 

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
What i meant was that you can only feed binary data or binary handlers to
chardet. You can decode the binary data according to the detection results
afterward.

On Wed, 22 Jul 2020 at 11:11 PM, Liu Zheng  wrote:

> Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and
> the chardet file handler are binary handlers. Binary handler presents the
> raw data. chardet takes a sequence or raw data and then detect the encoding
> format. With its prediction, if you want to open that puece of data in text
> mode, you can use the .decode() method of bytes object to
> get a python string.
>
> On Wed, 22 Jul 2020 at 11:04 PM, Kovy Jacob  wrote:
>
>> That’s probably not the proper answer, but that’s the best I can do.
>> Sorry :-(
>>
>>
>> On Jul 22, 2020, at 10:46 AM, Ronaldo Mata 
>> wrote:
>>
>> Yes, the problem here is that the files will be loaded by the user, so I
>> don't know what delimiter I will receive. This is not a base command that I
>> am using, it is the logic that I want to incorporate in a view
>>
>> El mié., 22 jul. 2020 a las 10:43, Kovy Jacob ()
>> escribió:
>>
>>> Ah, so is the problem that you don’t always know what the delimiter is
>>> when you read it? If yes, what is the use case for this? You might not need
>>> a universal solution, maybe just put all the info into a csv yourself,
>>> manually.
>>>
>>> On Jul 22, 2020, at 10:39 AM, Ronaldo Mata 
>>> wrote:
>>>
>>> Hi Kovy, I'm using csv module, but I need to handle the delimiters of
>>> the files, sometimes you come separated by "," others by ";" and rarely by
>>> "|"
>>>
>>> El mié., 22 jul. 2020 a las 10:28, Kovy Jacob ()
>>> escribió:
>>>
>>>> Could you just use the standard python csv module?
>>>>
>>>> On Jul 22, 2020, at 10:25 AM, Ronaldo Mata 
>>>> wrote:
>>>>
>>>> Hi Liu thank for your answer.
>>>>
>>>> This has been a headache, I am trying to read the file using
>>>> csv.DictReader initially i had an error trying to get the dict keys when
>>>> iterating by rows, and i thought it could be encoding (for this reason i
>>>> wanted to prepare the view to use the correct encoding). for that reason I
>>>> asked my question.
>>>>
>>>> 1) your first approach doesn't work, if i send utf-8 file, chardet
>>>> returns ascii as encoding. it seems request.FILES ['file']. read () returns
>>>> a binary with that encoding.
>>>>
>>>> 2) In the end I realized that the problem was the delimiter of the csv
>>>> but predicting it is another problem.
>>>>
>>>> Anyway, it was a task that I had to do and that was my limitation. I
>>>> think there must be a library that does all this, uploading a csv file is
>>>> common practice in many web apps.
>>>>
>>>> El mar., 21 jul. 2020 a las 13:47, Liu Zheng ()
>>>> escribió:
>>>>
>>>>> Hi. First of all, I think it's impossible to perfectly detect encoding
>>>>> without further information. See the answer in this SO post:
>>>>> https://stackoverflow.com/questions/436220/how-to-determine-the-encoding-of-text
>>>>>  There
>>>>> are many packages and tools to help detect encoding format, but keep in
>>>>> mind that they are only giving educated guesses. (Most of the time, the
>>>>> guess is correct, but do check the dev page to see whether there are known
>>>>> issues related to your problem.)
>>>>>
>>>>> Now let's say you have decided to use chardet. Check its doc page for
>>>>> the usage: https://chardet.readthedocs.io/en/latest/usage.html#usage 
>>>>> You'll
>>>>> have more than one solutions. Here are some examples:
>>>>>
>>>>> 1. If the files uploaded to your server are all expected to be small
>>>>> csv files (less than a few MB and not many users do it concurrently), you
>>>>> can do the following:
>>>>>
>>>>> #in the view to handle the uploaded file: (assume file input name is
>>>>> just "file")
>>>>> file_content = request.FILES['file'].read()
>>>>> chardet.detect(file_content)
>>>>>
>>>>> 2. Also, chardet seems to support incremental (line-by-line) detection
>>>>> https://chardet.readthedocs.io/en/latest/usage.html#example-

Re: Import csv file on django view

2020-07-22 Thread Liu Zheng
Hi, glad you solved the problem. Yes, both the request.FILES[‘file’] and
the chardet file handler are binary handlers. Binary handler presents the
raw data. chardet takes a sequence or raw data and then detect the encoding
format. With its prediction, if you want to open that puece of data in text
mode, you can use the .decode() method of bytes object to
get a python string.

On Wed, 22 Jul 2020 at 11:04 PM, Kovy Jacob  wrote:

> That’s probably not the proper answer, but that’s the best I can do. Sorry
> :-(
>
>
> On Jul 22, 2020, at 10:46 AM, Ronaldo Mata 
> wrote:
>
> Yes, the problem here is that the files will be loaded by the user, so I
> don't know what delimiter I will receive. This is not a base command that I
> am using, it is the logic that I want to incorporate in a view
>
> El mié., 22 jul. 2020 a las 10:43, Kovy Jacob ()
> escribió:
>
>> Ah, so is the problem that you don’t always know what the delimiter is
>> when you read it? If yes, what is the use case for this? You might not need
>> a universal solution, maybe just put all the info into a csv yourself,
>> manually.
>>
>> On Jul 22, 2020, at 10:39 AM, Ronaldo Mata 
>> wrote:
>>
>> Hi Kovy, I'm using csv module, but I need to handle the delimiters of the
>> files, sometimes you come separated by "," others by ";" and rarely by "|"
>>
>> El mié., 22 jul. 2020 a las 10:28, Kovy Jacob ()
>> escribió:
>>
>>> Could you just use the standard python csv module?
>>>
>>> On Jul 22, 2020, at 10:25 AM, Ronaldo Mata 
>>> wrote:
>>>
>>> Hi Liu thank for your answer.
>>>
>>> This has been a headache, I am trying to read the file using
>>> csv.DictReader initially i had an error trying to get the dict keys when
>>> iterating by rows, and i thought it could be encoding (for this reason i
>>> wanted to prepare the view to use the correct encoding). for that reason I
>>> asked my question.
>>>
>>> 1) your first approach doesn't work, if i send utf-8 file, chardet
>>> returns ascii as encoding. it seems request.FILES ['file']. read () returns
>>> a binary with that encoding.
>>>
>>> 2) In the end I realized that the problem was the delimiter of the csv
>>> but predicting it is another problem.
>>>
>>> Anyway, it was a task that I had to do and that was my limitation. I
>>> think there must be a library that does all this, uploading a csv file is
>>> common practice in many web apps.
>>>
>>> El mar., 21 jul. 2020 a las 13:47, Liu Zheng ()
>>> escribió:
>>>
>>>> Hi. First of all, I think it's impossible to perfectly detect encoding
>>>> without further information. See the answer in this SO post:
>>>> https://stackoverflow.com/questions/436220/how-to-determine-the-encoding-of-text
>>>>  There
>>>> are many packages and tools to help detect encoding format, but keep in
>>>> mind that they are only giving educated guesses. (Most of the time, the
>>>> guess is correct, but do check the dev page to see whether there are known
>>>> issues related to your problem.)
>>>>
>>>> Now let's say you have decided to use chardet. Check its doc page for
>>>> the usage: https://chardet.readthedocs.io/en/latest/usage.html#usage You'll
>>>> have more than one solutions. Here are some examples:
>>>>
>>>> 1. If the files uploaded to your server are all expected to be small
>>>> csv files (less than a few MB and not many users do it concurrently), you
>>>> can do the following:
>>>>
>>>> #in the view to handle the uploaded file: (assume file input name is
>>>> just "file")
>>>> file_content = request.FILES['file'].read()
>>>> chardet.detect(file_content)
>>>>
>>>> 2. Also, chardet seems to support incremental (line-by-line) detection
>>>> https://chardet.readthedocs.io/en/latest/usage.html#example-detecting-encoding-incrementally
>>>>
>>>> Given this, we can also read from requests.FILES line by line and pass
>>>> each line to chardet
>>>>
>>>> from chardet.universaldetector import UniversalDetector
>>>>
>>>> #somewhere in a view function
>>>> detector = UniversalDetector()
>>>> file_handle = request.FILES['file']
>>>> for line in file_handle:
>>>> detector.feed(line)
>>>> if detector.done: break
>>>> detector.close()
>>>&

Re: Import csv file on django view

2020-07-21 Thread Liu Zheng
Hi. First of all, I think it's impossible to perfectly detect encoding 
without further information. See the answer in this SO post: 
https://stackoverflow.com/questions/436220/how-to-determine-the-encoding-of-text
 There 
are many packages and tools to help detect encoding format, but keep in 
mind that they are only giving educated guesses. (Most of the time, the 
guess is correct, but do check the dev page to see whether there are known 
issues related to your problem.)

Now let's say you have decided to use chardet. Check its doc page for the 
usage: https://chardet.readthedocs.io/en/latest/usage.html#usage You'll 
have more than one solutions. Here are some examples:

1. If the files uploaded to your server are all expected to be small csv 
files (less than a few MB and not many users do it concurrently), you can 
do the following:

#in the view to handle the uploaded file: (assume file input name is just 
"file")
file_content = request.FILES['file'].read()
chardet.detect(file_content)

2. Also, chardet seems to support incremental (line-by-line) detection 
https://chardet.readthedocs.io/en/latest/usage.html#example-detecting-encoding-incrementally

Given this, we can also read from requests.FILES line by line and pass each 
line to chardet

from chardet.universaldetector import UniversalDetector

#somewhere in a view function
detector = UniversalDetector()
file_handle = request.FILES['file']
for line in file_handle:
detector.feed(line)
if detector.done: break
detector.close()
# result available as a dict at detector.result





On Tuesday, July 21, 2020 at 7:09:35 AM UTC+8, Ronaldo Mata wrote:
>
> How to deal with encoding when you try to read a csv file on view.
>
> I have a view to upload csv file, in this view I read file and save each 
> row as new record.
>
> My bug is when I try to upload a csv file with a differente encoding (not 
> UTF-8)
>
> how to handle this on django (using request.FILES) I was researching and I 
> found chardet but I don't know how to pass it a request.FILES. I need help 
> please.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64307441-0e65-45a2-b917-ece15a4ea729o%40googlegroups.com.


Where to check detailed info (reference page, not the topics page) about contrib.auth.views.LogoutView?

2020-07-21 Thread Liu Zheng
Hi guys,

I'm trying to solve a simple problem: add a message "You've logged out!" 
After redirecting user to login page. I got one nice solution at 
https://stackoverflow.com/questions/11393929/django-message-when-logout

from django.contrib.auth.views import LogoutView

class YourCustomLogoutView(LogoutView):

def get_next_page(self):
next_page = super(YourCustomLogoutView, self).get_next_page()
messages.add_message(
self.request, messages.SUCCESS,
'You successfully log out!'
)
return next_page


This made me interested in checking what methods are available in 
LogoutView and which are good to be overloaded. I then was looking for the 
reference page in Django's doc.

I found several lines about `LogoutView` 
in 
https://docs.djangoproject.com/en/3.0/topics/auth/default/#django.contrib.auth.views.LogoutView,
 
but not every method of this class was given here. I know Django's doc has 
tutorials, topics and refs, ordered by detailedness. However, when I tried 
to use the search bar in django's website, also didn't get a ref page for 
LogoutView. (Also cannot find such a page in google)

This question can be generalized: If I'm looking for the detailed 
information of some django object, how can I obtain it efficiently?


Thanks and regards,
Zheng

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f2c47ae9-63a6-437c-bd53-1ec9e75b520eo%40googlegroups.com.


Re: Using primary key to update via POST request.

2020-07-21 Thread Liu Zheng
Hi, do you mean in the GET request, the user provides the pk (perhaps in
URL) or the server sends to users an object where pk is a field?

If it's the former, then @George's answer is the right one. An example of
what you are trying to achieve will be helpful.

Best
Zheng

On Tue, Jul 21, 2020 at 1:05 AM George  wrote:

> You use request.GET['choice_filed']
>
> On Monday, July 20, 2020 at 9:14:48 AM UTC+5:30, Arpana Mehta wrote:
>>
>> Hi,
>> I have a class with a GET and a POST request. I am sending the data (
>> with pk of the object ) in my GET request and I want the frontend to use
>> that pk to refer to the exact instance of the model whenever doing any
>> operation.
>>
>> In my POST request I am only sending the `choice field` value. How do I
>> use the pk received in GET?
>>
>> Thanks and regards,
>> Arpana Mehta
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/75e78c32-6736-45a0-ab66-9406dc87dc5do%40googlegroups.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf9yD2GW%3DZbihCcaJWK%2BtQ%2Bodv_yVOtuhe%2Bf_YtBs8wSTQ%40mail.gmail.com.


Re: My first question

2020-07-20 Thread Liu Zheng
Hi. Yes. You are absolutely right. I'm new to google groups (in fact, this 
was my first post). I thought I could edit it after posting it out. Was a 
bit in a hurry when writing it down. :O
Also a bit wordy...

On Monday, July 20, 2020 at 8:05:35 PM UTC+8, ajoeiam wrote:
>
> Appreciate very much your informative post. Question below - - - 
>
> On Sat, Jul 18, 2020 at 9:14 AM Liu Zheng  > wrote:
>
>> Hi. Doesn't sound like a Django question, but I assume you came across 
>> this question when writing Django codes:) So anyway, let me try to see 
>> whether I could provide any useful information here.
>>
>> This question is a bit too broad, so let me try to answer it in several 
>> levels.
>>
>> First, python doesn't care the format of any file. From python's point of 
>> view, any file is just a sequence of binary data. On the lowest level, 
>> python only two types of operations: read N bytes from the file starting 
>> from a position; write N bytes to the file starting from a position. That's 
>> it. What each byte mean is up to the programmers. So on the level of python 
>> programming, there's no difference between a txt file and a csv file.
>>
>> Having said the first point, there are standard formats defined by 
>> programmers, to make communication easier. First, among all binary files, 
>> there's special type of files called "text files". It's special because 
>> every byte of a text file must be a value from a certain table of symbols 
>> (think of the ASCII table). Not all files are text files. But if a file is 
>> a text file, then most text editors can handle that file well. (Python also 
>> have native support on the language level, that is, you open a file in the 
>> text mode if you use "open(, 'r')" intead of "open(, 
>> 'rb')". However, this is only for sake of convenience of human readability. 
>> It doesn't make a text file fundamentally different from other files. In 
>> fact, you can open a text file in the binary mode using 'rb'. Python will 
>> simply forget that the file is a text file.
>>
>> Next, text files still form a big family. By assigning meanings to 
>> different symbols and creating rules of how the content should look like, 
>> there are more types under text files. csv is a special type of text file. 
>> (Example of othe types are .py, .html, etc). Since it's just a text file, 
>> you can open a csv file using "open(, 'r')" and do 
>> read/write operations like any other text file. However, since it has its 
>> own rules, there are also some helper libraries to assist you handling csv 
>> files, too. Examples are "csv" package, "pandas" package, etc. But again, 
>> since it's a text file, you can ignore those packages and write your codes 
>> using string functions directly. For example:
>>
>> ```
>> s = open("sample.csv", 'r').read()
>> lines = s.split('\n')
>> first_line = lines[0]
>> columns_lables = first_line.split(',')
>> ..
>> ```
>>
>> Such a piece of codes will handle a very simple and standard csv file 
>> already. However, csv has more complications than this. It even has 
>> different variations (called dialets). 
>>
>
> Did you mean dialects instead of dialets by any chance?
>  
>
>> If treating a csv file as an ordinary text file, you are basically 
>> re-inventing the wheel. (There's nothing wrong with that. Just tedious.) 
>> Those standard packages can handle those staff and let you focus on your 
>> business logic. That's all.
>>
>> In the end, I want to emphasize that files' extension names doesn't mean 
>> anything. When I said a csv file above, I don't mean a file whose file name 
>> ends with ".csv". I mean a file whose content complies the csv rules. By 
>> creating a file called "something.csv", I'm merely giving a promise to 
>> anyone who open it that "I promise you that the content in this file 
>> satisfies the csv rules. You have my words!" Whether I keep my promise or 
>> not is totally up to me (indeed, I can rename an image file "pic1.jpg" to 
>> "pic1.csv".) In addition, you can save some csv data into a .txt files. For 
>> example, consider the following data:
>>
>> Name,Job Title,Phone Number
>> Alice,Manager,23121212
>> Bob,Director,12345678
>> Chales,Developer,41212113
>>
>> You can store the data into "contacts.txt". I will still call it a csv 
>> file even though it has ".txt" extension. Therefore, I can handle this file 
>> u

Re: My first question

2020-07-20 Thread Liu Zheng
Hi Derek. I just copy pasted the answer to my blog (haven't written any 
blog in recent months). Will improve it into a readable blog post with 
better presentaion. Thanks for suggesting this. Acknowledgement was given 
in the post, but let me know if you are not comfortable of being mentioned 
:)

On Monday, July 20, 2020 at 2:25:00 PM UTC+8, Derek wrote:
>
> This would make a great blog post!  And in future, we can all refer 
> directly to it, when someone asks a similar question.
>
> On Saturday, 18 July 2020 16:13:53 UTC+2, Liu Zheng wrote:
>>
>> Hi. Doesn't sound like a Django question, but I assume you came across 
>> this question when writing Django codes:) So anyway, let me try to see 
>> whether I could provide any useful information here.
>>
>> This question is a bit too broad, so let me try to answer it in several 
>> levels.
>>
>> First, python doesn't care the format of any file. From python's point of 
>> view, any file is just a sequence of binary data. On the lowest level, 
>> python only two types of operations: read N bytes from the file starting 
>> from a position; write N bytes to the file starting from a position. That's 
>> it. What each byte mean is up to the programmers. So on the level of python 
>> programming, there's no difference between a txt file and a csv file.
>>
>> Having said the first point, there are standard formats defined by 
>> programmers, to make communication easier. First, among all binary files, 
>> there's special type of files called "text files". It's special because 
>> every byte of a text file must be a value from a certain table of symbols 
>> (think of the ASCII table). Not all files are text files. But if a file is 
>> a text file, then most text editors can handle that file well. (Python also 
>> have native support on the language level, that is, you open a file in the 
>> text mode if you use "open(, 'r')" intead of "open(, 
>> 'rb')". However, this is only for sake of convenience of human readability. 
>> It doesn't make a text file fundamentally different from other files. In 
>> fact, you can open a text file in the binary mode using 'rb'. Python will 
>> simply forget that the file is a text file.
>>
>> Next, text files still form a big family. By assigning meanings to 
>> different symbols and creating rules of how the content should look like, 
>> there are more types under text files. csv is a special type of text file. 
>> (Example of othe types are .py, .html, etc). Since it's just a text file, 
>> you can open a csv file using "open(, 'r')" and do 
>> read/write operations like any other text file. However, since it has its 
>> own rules, there are also some helper libraries to assist you handling csv 
>> files, too. Examples are "csv" package, "pandas" package, etc. But again, 
>> since it's a text file, you can ignore those packages and write your codes 
>> using string functions directly. For example:
>>
>> ```
>> s = open("sample.csv", 'r').read()
>> lines = s.split('\n')
>> first_line = lines[0]
>> columns_lables = first_line.split(',')
>> ..
>> ```
>>
>> Such a piece of codes will handle a very simple and standard csv file 
>> already. However, csv has more complications than this. It even has 
>> different variations (called dialets). If treating a csv file as an 
>> ordinary text file, you are basically re-inventing the wheel. (There's 
>> nothing wrong with that. Just tedious.) Those standard packages can handle 
>> those staff and let you focus on your business logic. That's all.
>>
>> In the end, I want to emphasize that files' extension names doesn't mean 
>> anything. When I said a csv file above, I don't mean a file whose file name 
>> ends with ".csv". I mean a file whose content complies the csv rules. By 
>> creating a file called "something.csv", I'm merely giving a promise to 
>> anyone who open it that "I promise you that the content in this file 
>> satisfies the csv rules. You have my words!" Whether I keep my promise or 
>> not is totally up to me (indeed, I can rename an image file "pic1.jpg" to 
>> "pic1.csv".) In addition, you can save some csv data into a .txt files. For 
>> example, consider the following data:
>>
>> Name,Job Title,Phone Number
>> Alice,Manager,23121212
>> Bob,Director,12345678
>> Chales,Developer,41212113
>>
>> You can store the data into "contacts.txt". I will still call it a csv 
>> file even though it has ".txt" e

Re: Login and Registration

2020-07-19 Thread Liu Zheng
https://www.youtube.com/playlist?list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p
This video series will be helpful

On Mon, Jul 20, 2020 at 5:33 AM Anirudh choudhary <
anirudhchoudary...@gmail.com> wrote:

> You can simply do it by manipulating the context data like
>
> context = {
>  'form_login':loginform,
>  'form_signup' :signupform
>
>  }
>
> Thanks
>
> On Sun, 19 Jul, 2020, 11:10 PM Exactly musty, 
> wrote:
>
>> Read the doc or follow MDN tutorial
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/2aa0a800-6387-43ce-ac1e-385807bd7e44o%40googlegroups.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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL8_rkEWdKOKHMTzmUDOG0_n0n6XFkdcoPQpjgxLamLeqYoaYA%40mail.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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGQ3pf8j%3Dr2vvS6hRjgga%3D5z5g5C1WF0SLvowdRrUiOQSPxyGg%40mail.gmail.com.


Re: How to save images posted by application users

2020-07-18 Thread Liu Zheng
Hi. Here's a very nice video tutorial on how to handle images with media. 
https://www.youtube.com/watch?v=FdVuKt_iuSI=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p=8

Also to your question on how to deploy it in production, check this video. 
https://www.youtube.com/watch?v=Sa_kQheCnds=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p=13

On Thursday, July 16, 2020 at 1:08:08 PM UTC+8, Ram wrote:
>
> Hi,
>
> We need to save images posted by our application users and the images will 
> be displayed in application UI once they are saved successfully. We are 
> trying with these parameters in our settings.py but they are not working 
> and our OS platform is Windows 10 OS. We know file paths are different in 
> Windows OS when compared to non Windows OS platforms. Did anyone use Window 
> OS in this community and able to save image successfully?
>
> STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
>> STATIC_URL = '/static/'
>>
>>
>> MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
>> MEDIA_URL = '/media/'
>>
>>
> Another challenge that we have is  that the above question is related to 
> development, becase we use Windows laptop for our application evelopment, 
> but once the code is integrated we need to deploy the code in our hosting 
> server that is running with Linux OS. So we are not sure how to handle the 
> case of multi OS platforms?
>
> I'm sure many people could have resolved this in their applications. I 
> appreciate if you can share suitabe recommendations?
>
> Best regards
>  
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ee01fd9-7d32-4bfc-89da-d057df415fcfo%40googlegroups.com.


Re: My first question

2020-07-18 Thread Liu Zheng
Hi. Doesn't sound like a Django question, but I assume you came across this 
question when writing Django codes:) So anyway, let me try to see whether I 
could provide any useful information here.

This question is a bit too broad, so let me try to answer it in several 
levels.

First, python doesn't care the format of any file. From python's point of 
view, any file is just a sequence of binary data. On the lowest level, 
python only two types of operations: read N bytes from the file starting 
from a position; write N bytes to the file starting from a position. That's 
it. What each byte mean is up to the programmers. So on the level of python 
programming, there's no difference between a txt file and a csv file.

Having said the first point, there are standard formats defined by 
programmers, to make communication easier. First, among all binary files, 
there's special type of files called "text files". It's special because 
every byte of a text file must be a value from a certain table of symbols 
(think of the ASCII table). Not all files are text files. But if a file is 
a text file, then most text editors can handle that file well. (Python also 
have native support on the language level, that is, you open a file in the 
text mode if you use "open(, 'r')" intead of "open(, 
'rb')". However, this is only for sake of convenience of human readability. 
It doesn't make a text file fundamentally different from other files. In 
fact, you can open a text file in the binary mode using 'rb'. Python will 
simply forget that the file is a text file.

Next, text files still form a big family. By assigning meanings to 
different symbols and creating rules of how the content should look like, 
there are more types under text files. csv is a special type of text file. 
(Example of othe types are .py, .html, etc). Since it's just a text file, 
you can open a csv file using "open(, 'r')" and do 
read/write operations like any other text file. However, since it has its 
own rules, there are also some helper libraries to assist you handling csv 
files, too. Examples are "csv" package, "pandas" package, etc. But again, 
since it's a text file, you can ignore those packages and write your codes 
using string functions directly. For example:

```
s = open("sample.csv", 'r').read()
lines = s.split('\n')
first_line = lines[0]
columns_lables = first_line.split(',')
..
```

Such a piece of codes will handle a very simple and standard csv file 
already. However, csv has more complications than this. It even has 
different variations (called dialets). If treating a csv file as an 
ordinary text file, you are basically re-inventing the wheel. (There's 
nothing wrong with that. Just tedious.) Those standard packages can handle 
those staff and let you focus on your business logic. That's all.

In the end, I want to emphasize that files' extension names doesn't mean 
anything. When I said a csv file above, I don't mean a file whose file name 
ends with ".csv". I mean a file whose content complies the csv rules. By 
creating a file called "something.csv", I'm merely giving a promise to 
anyone who open it that "I promise you that the content in this file 
satisfies the csv rules. You have my words!" Whether I keep my promise or 
not is totally up to me (indeed, I can rename an image file "pic1.jpg" to 
"pic1.csv".) In addition, you can save some csv data into a .txt files. For 
example, consider the following data:

Name,Job Title,Phone Number
Alice,Manager,23121212
Bob,Director,12345678
Chales,Developer,41212113

You can store the data into "contacts.txt". I will still call it a csv file 
even though it has ".txt" extension. Therefore, I can handle this file 
using any csv package. For example:

```
import pandas as pd
df = pd.read_csv("contacts.txt")
...
```

Pandas will not complain just because its extension is not ".csv". However, 
it will be a good practice to choose the extension which best describes the 
nature of the file's contents. In this way, you'll bring less confusion to 
the users of this file (including the future yourself).



On Saturday, July 18, 2020 at 2:25:57 PM UTC+8, Sead Sejo Gicić wrote:
>
> What is the difference between ordinary txt file and csv file for using in 
> Python programming?
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a9b233b-a61b-4866-8383-44b4b60ac736o%40googlegroups.com.


Re: can't find index

2020-07-18 Thread Liu Zheng
I believe you were following the official tutorial on Django's website, and 
has created a view function called "index" in "polls" app, which was wired 
to "/polls" url. All the codes were exactly the same as provided in the 
tutorial. The mistake you made was when you opened the browser and typed 
"http://localhost:8000/index;. You shouldn't view "/index". It's the name 
of the view function, not the name of the end point. As you can see on the 
error page, you provided views at "polls/" and "admin/". So you just go to 
"http://localhost:8000/polls; and will see your page there.

On Saturday, July 18, 2020 at 5:21:25 AM UTC+8, Ralph Barhydt wrote:
>
>
> I have done the first part of the tutorial many times and suddenly, doing 
> it one more time, I get this message.  I am in the right directory and I 
> have checked the code in urls.py many time as well.  What is going on?
>
>
>
>
>
> ```
> Page not found (404)
> Request Method: GET
> Request URL: http://localhost:8000/index
>
> Using the URLconf defined in rbsite.urls, Django tried these URL 
> patterns, in this order:
>
>1. polls/
>2. admin/
>
> The current path, index, didn't match any of these.
>
> You're seeing this error because you have DEBUG = True in your Django 
> settings file. Change that to False, and Django will display a standard 
> 404 page.
>
> ```
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fedc1637-3f79-43ce-a47e-f7b7e3531451o%40googlegroups.com.