simple command line ./manage.py shell puzzle
Why does this fail?... % echo "import datetime ; [datetime for e in [1, 2]]" > test % ./manage.py shell < test Traceback (most recent call last): File "./manage.py", line 8, in django.core.management.execute_from_command_line(sys.argv) File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", line 92, in handle exec(sys.stdin.read()) File "", line 1, in File "", line 1, in NameError: name 'datetime' is not defined -- 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/f8990c95-023a-4380-8551-8d0f3ca64fa7n%40googlegroups.com.
Re: simple command line ./manage.py shell puzzle
The script should quietly exist without error. I actually have a longer script that is the real workhorse. I just made this tiny one to showcase the issue. I can past import datetime ; [datetime for e in [1, 2]] into a regular Python3 shell as well as the Django shell and all is fine. The problem I think has something to do with how I inject it into the Django shell via "< test". cs On Thursday, April 21, 2022 at 12:18:04 PM UTC-5 larry.mart...@gmail.com wrote: > On Thu, Apr 21, 2022 at 1:06 PM cseb...@gmail.com > wrote: > > > > Why does this fail?... > > > > % echo "import datetime ; [datetime for e in [1, 2]]" > test > > > > % ./manage.py shell < test > > > > Traceback (most recent call last): > > File "./manage.py", line 8, in > > django.core.management.execute_from_command_line(sys.argv) > > File > "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line > 381, in execute_from_command_line > > utility.execute() > > File > "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line > 375, in execute > > self.fetch_command(subcommand).run_from_argv(self.argv) > > File "/usr/lib/python3/dist-packages/django/core/management/base.py", > line 323, in run_from_argv > > self.execute(*args, **cmd_options) > > File "/usr/lib/python3/dist-packages/django/core/management/base.py", > line 364, in execute > > output = self.handle(*args, **options) > > File > "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", > line 92, in handle > > exec(sys.stdin.read()) > > File "", line 1, in > > File "", line 1, in > > NameError: name 'datetime' is not defined > > What do you expect 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/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%40googlegroups.com.
Re: simple command line ./manage.py shell puzzle
Antonis Thanks. Here are the answers to your questions... OS: Ubuntu 20.04.3 LTS Django version: 2:2.2.12-1ubuntu0.11 Django shell version: Python 3.8.10 Chris On Friday, April 22, 2022 at 2:00:17 AM UTC-5 Antonis Christofides wrote: > It works fine here. I entered your commands exactly and the second one > does not provide any output. > > What shell do you have? And what version of Python and Django? And what OS? > > On 21/04/2022 22.28, cseb...@gmail.com wrote: > > Yes I agree. But why does it complain that datetime doesn't exist when I > do " ./manage.py shell < test " ? > > Shouldn't it also not do anything like when I paste into a Python3 or > Django shell as you did? > > cs > > On Thursday, April 21, 2022 at 2:10:39 PM UTC-5 larry@gmail.com wrote: > >> On Thu, Apr 21, 2022 at 2:53 PM cseb...@gmail.com >> wrote: >> > >> > The script should quietly exist without error. >> > >> > I actually have a longer script that is the real workhorse. >> > I just made this tiny one to showcase the issue. >> > >> > I can past >> > >> > import datetime ; [datetime for e in [1, 2]] >> > >> > into a regular Python3 shell as well as the Django shell and all is >> fine. >> >> $ python3 >> Python 3.8.10 (v3.8.10:3d8993a744, May 3 2021, 08:55:58) >> [Clang 6.0 (clang-600.0.57)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import datetime ; [datetime for e in [1, 2]] >> [> '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>, >> >> >> > '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>] >> >> >> >> It does not do anything. >> >> > >> > The problem I think has something to do with how I inject >> > it into the Django shell via "< test". >> > >> > cs >> > On Thursday, April 21, 2022 at 12:18:04 PM UTC-5 larry@gmail.com >> wrote: >> >> >> >> On Thu, Apr 21, 2022 at 1:06 PM cseb...@gmail.com >> wrote: >> >> > >> >> > Why does this fail?... >> >> > >> >> > % echo "import datetime ; [datetime for e in [1, 2]]" > test >> >> > >> >> > % ./manage.py shell < test >> >> > >> >> > Traceback (most recent call last): >> >> > File "./manage.py", line 8, in >> >> > django.core.management.execute_from_command_line(sys.argv) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line >> 381, in execute_from_command_line >> >> > utility.execute() >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line >> 375, in execute >> >> > self.fetch_command(subcommand).run_from_argv(self.argv) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/base.py", line 323, >> in run_from_argv >> >> > self.execute(*args, **cmd_options) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/base.py", line 364, >> in execute >> >> > output = self.handle(*args, **options) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", >> line 92, in handle >> >> > exec(sys.stdin.read()) >> >> > File "", line 1, in >> >> > File "", line 1, in >> >> > NameError: name 'datetime' is not defined >> >> >> >> What do you expect 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...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%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/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > -- 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/957c09ab-3b22-4a36-8bd0-5865b01a7875n%40googlegroups.com.
Re: simple command line ./manage.py shell puzzle
After some more investigating. All the issues seem to be because of the FOR LOOP. For some strange reason, when I pipe in the Python code you can't have a for loop that way. cs On Friday, April 22, 2022 at 2:00:17 AM UTC-5 Antonis Christofides wrote: > It works fine here. I entered your commands exactly and the second one > does not provide any output. > > What shell do you have? And what version of Python and Django? And what OS? > > On 21/04/2022 22.28, cseb...@gmail.com wrote: > > Yes I agree. But why does it complain that datetime doesn't exist when I > do " ./manage.py shell < test " ? > > Shouldn't it also not do anything like when I paste into a Python3 or > Django shell as you did? > > cs > > On Thursday, April 21, 2022 at 2:10:39 PM UTC-5 larry@gmail.com wrote: > >> On Thu, Apr 21, 2022 at 2:53 PM cseb...@gmail.com >> wrote: >> > >> > The script should quietly exist without error. >> > >> > I actually have a longer script that is the real workhorse. >> > I just made this tiny one to showcase the issue. >> > >> > I can past >> > >> > import datetime ; [datetime for e in [1, 2]] >> > >> > into a regular Python3 shell as well as the Django shell and all is >> fine. >> >> $ python3 >> Python 3.8.10 (v3.8.10:3d8993a744, May 3 2021, 08:55:58) >> [Clang 6.0 (clang-600.0.57)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import datetime ; [datetime for e in [1, 2]] >> [> '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>, >> >> >> > '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>] >> >> >> >> It does not do anything. >> >> > >> > The problem I think has something to do with how I inject >> > it into the Django shell via "< test". >> > >> > cs >> > On Thursday, April 21, 2022 at 12:18:04 PM UTC-5 larry@gmail.com >> wrote: >> >> >> >> On Thu, Apr 21, 2022 at 1:06 PM cseb...@gmail.com >> wrote: >> >> > >> >> > Why does this fail?... >> >> > >> >> > % echo "import datetime ; [datetime for e in [1, 2]]" > test >> >> > >> >> > % ./manage.py shell < test >> >> > >> >> > Traceback (most recent call last): >> >> > File "./manage.py", line 8, in >> >> > django.core.management.execute_from_command_line(sys.argv) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line >> 381, in execute_from_command_line >> >> > utility.execute() >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line >> 375, in execute >> >> > self.fetch_command(subcommand).run_from_argv(self.argv) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/base.py", line 323, >> in run_from_argv >> >> > self.execute(*args, **cmd_options) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/base.py", line 364, >> in execute >> >> > output = self.handle(*args, **options) >> >> > File >> "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", >> line 92, in handle >> >> > exec(sys.stdin.read()) >> >> > File "", line 1, in >> >> > File "", line 1, in >> >> > NameError: name 'datetime' is not defined >> >> >> >> What do you expect 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...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%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/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > -- 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/bd37f0fa-81c1-4c5d-be36-6ebef919d181n%40googlegroups.com.
Recommendation for effective captcha systems?
I used some Django package called captcha but it seems spammers can bypass it. Is there a pretty nearly foolproof captcha people use 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/cafa536a-b27c-4bce-857d-e29760a26a5dn%40googlegroups.com.
How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts?
How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts? There seem to be a number of imports needed to make the 2nd version work. cs -- 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/388530f4-7089-4e58-a5e9-6cb436f2cb5cn%40googlegroups.com.
Re: How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts?
Thanks. Works great! On Monday, June 6, 2022 at 9:44:39 PM UTC-5 juw...@gmail.com wrote: > You can add the following lines in your script: > > ` > import django > sys.path.append('') > os.environ.setdefault('DJANGO_SETTINGS_MODULE', '') > django.setup() > ` > > On Tue, 7 Jun 2022 at 04:17, Jason wrote: > >> Why? what's the purpose behind this? >> >> On Monday, June 6, 2022 at 12:27:58 PM UTC-4 cseb...@gmail.com wrote: >> >>> How replace "./manage.py < some_code.py" with "./some_code.py" for >>> website scripts? >>> >>> There seem to be a number of imports needed to make the 2nd version work. >>> >>> cs >>> >> -- >> 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/72eaa595-0d6c-44d3-a612-4776b0624c6dn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/72eaa595-0d6c-44d3-a612-4776b0624c6dn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/6c7fca4e-c708-4122-86e7-bc9e7ff3cbc0n%40googlegroups.com.
Re: How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts?
Don't you sometimes have housekeeping chores that are done by scripts? Often those scripts want to access the ORM such as to update something in the database. I'm aware of notion of creating custom ./manage.py commands but a standalone scripts seems easier no? cs On Monday, June 6, 2022 at 3:17:29 PM UTC-5 Jason wrote: > Why? what's the purpose behind this? > > On Monday, June 6, 2022 at 12:27:58 PM UTC-4 cseb...@gmail.com wrote: > >> How replace "./manage.py < some_code.py" with "./some_code.py" for >> website scripts? >> >> There seem to be a number of imports needed to make the 2nd version work. >> >> cs >> > -- 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/8051edeb-698e-44d4-9ff8-ddd9a6472bf7n%40googlegroups.com.
Removing "Invalid HTTP_HOST header" msgs with nginx.conf default server NOT working
I constantly get the errors below in my Django server logs. To try to remove this, I added this to my Nginx server's nginx.conf file but it didn't work server { listen 80 default_server; return 444; } What else can I do to remove these errors below this line??? Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109:443'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. Invalid HTTP_HOST header: '3.208.32.109'. You may need to add '3.208.32.109' to ALLOWED_HOSTS. -- 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/d7dc260c-e271-41a3-9655-cce36a7b371an%40googlegroups.com.
Re: Removing "Invalid HTTP_HOST header" msgs with nginx.conf default server NOT working
Thanks so much. I'll try it. And your solution has no need for Nginx tweaking. I love it. cs On Sunday, June 26, 2022 at 12:50:02 PM UTC-5 Mr.Teapot wrote: > Please take a look on the ALLOWED_HOSTS documentation > https://docs.djangoproject.com/en/4.0/ref/settings/#allowed-hosts. > > *A list of strings representing the host/domain names that this Django > site can serve. This is a security measure to prevent HTTP Host header > attacks > <https://docs.djangoproject.com/en/4.0/topics/security/#host-headers-virtual-hosting>, > > which are possible even under many seemingly-safe web server > configurations.* > > Assuming 3.208.32.109 is your server IP you should add it to ALLOWED_HOSTS. > > piątek, 24 czerwca 2022 o 19:00:23 UTC+2 cseb...@gmail.com napisał(a): > >> I constantly get the errors below in my Django server logs. To try to >> remove this, >> I added this to my Nginx server's nginx.conf file but it didn't work >> >> server { >> >> listen 80 default_server; >> >> return 444; >> >> } >> >> What else can I do to remove these errors below this line??? >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109:443'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> Invalid HTTP_HOST header: '3.208.32.109'. You may need to add >> '3.208.32.109' to ALLOWED_HOSTS. >> >> -- 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/9fa70a36-d8ce-49d1-bc21-46e17d89dedfn%40googlegroups.com.
Why turning off these uWSGI options fixed problem with 100% CPU spikes and freezing?
One Django website was freezing about every HOUR with no indication in logs what the problem was. I was seeing CPU utilization spike to 100%. I removed these switches below and it seemed to have fixed the problem. --master --enable-threads --pcre-jit --thunder-lock Is there some problem with threads or something? What is weirder is that everything has been fine for MONTHS. I didn't change anything so not sure why this week uWSGI started blowing up. Here is my system info: uWSGI version:2.0.19.1 Django version: 2:2.2.12-1ubuntu0.7 on Ubuntu 20.04 LTS with following Linux kernel: Linux server 5.4.0-1030-aws #31-Ubuntu SMP Fri Nov 13 11:40:37 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux Sincerely, Chris -- 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/dd8d921f-01a7-4a51-9482-a9696a423c3fn%40googlegroups.com.
Re: Why turning off these uWSGI options fixed problem with 100% CPU spikes and freezing?
UPDATE: The Django app stays up longer without these switches but now after about half a day the MEMORY spikes? I'm seeing the % memory used go up to around 80% which again freezes this Django app. I'm enabling verbose logs now. Any idea what would cause this behavior? cs -- 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/98c1107f-903d-480b-a6b8-1f8ab732d2aen%40googlegroups.com.
Basic questions about scaling a Django web app. (e.g. AppEngine solves all problems?)
I have a simple web app (bighelp.business). I anticipate the number of users to steadily increase. I'm having nightmares of having to guesstimate how much extra RAM and cores to add every week. Furthermore, WSGI has these switches I use... --processes=5 and --max-requests=50. I don't know how I should alter these as my userbase grows and I don't want to guesstimate. How to others deal with growth? By the way, if I port my Django app to Google App Engine, does it automatically solve all these problems or is that just wishful thinking? Thanks! Chris -- 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/7bb16367-44fa-4593-9826-968a0084adbbn%40googlegroups.com.
What is different about "./manage.py shell" vs. normal Python shell that makes this list comprehension not work anymore?
I noticed a list comprehension bombs in the "./manage.py shell" shell that I think would be ok in normal Python shell. What is different about "./manage.py shell" that makes it not like certain list comprehensions? Here is the code erase that I run this way..."./manage.py shell < erase" import bighelp.models ACCT = bighelp.models.Account ASERV = bighelp.models.AccountService APPT = bighelp.models.Appointment for e in ACCT.objects.all()[:1]: appts = APPT.objects.filter(account = e)[:3] aservs = ASERV.objects.filter(account = e) allowed = [e.service.name for e in aservs] print(f"allowed is a list of strings => {allowed}\n\n") print(f"appts is a collection of Django objects => {appts}\n\n") print("This way of defining servs works...\n\n") servs = [] for a in appts: if a.service in allowed: servs.append(a.service) print(f"servs = {servs}\n\n") print("This way gives a mysterious error...\n\n") servs = [a.service for a in appts if (a.service in allowed)] ***THE OUTPUT ../manage.py shell < ./erase allowed is a list of strings => ['pet', 'cleaning'] appts is a collection of Django objects => , , ]> This way of defining servs works... servs = ['cleaning', 'pet', 'cleaning'] This way gives a mysterious error... Traceback (most recent call last): File "../manage.py", line 8, in django.core.management.execute_from_command_line(sys.argv) File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/usr/lib/python3/dist-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", line 92, in handle exec(sys.stdin.read()) File "", line 26, in File "", line 26, in NameError: name 'allowed' is not defined -- 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/a0fa5dcc-2861-411b-90fc-951ef6d8d58fn%40googlegroups.com.
How send data to Django app using Javascript or JQuery? (Having trouble doing a POST)
How send data from client Javascript to Django server? I tried the following but it didn't work. I want to read "token" cookie value and send to server but it never receives it as a valid form. Any sample working code greatly appreciated. function start_processing() { path = document.getElementById("path_inp").value; token = ""; csrf = "" kvps = document.cookie.split(";"); for(i = 0; i < kvps.length; i++) { if (kvps[i].split("=")[0].trim() == "token") { token = kvps[i].split("=")[1].trim(); } if (kvps[i].split("=")[0].trim() == "csrftoken") { csrf = kvps[i].split("=")[1].trim(); } } alert(path + " " + token + " " + csrf); $.post("/extraction", {"path" : path, "token" : token, "csrftoken" : csrf}); } -- 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/22bad142-aae0-4cfd-a2b2-7f8e2126b65dn%40googlegroups.com.
django.contrib.auth.update_session_auth_hash not working after change password
When I change a password, users are logged out. Django recommends keeping users logged in by calling django.contrib.auth.update_session_auth_hash(request, user). This is not working in a Django website of mine. They must log in again!? There are no error messages. Is there any way I can provide more details? Chris -- 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 visit https://groups.google.com/d/msgid/django-users/04908d1c-a1e4-41ea-afd8-e227f78af8bcn%40googlegroups.com.
Re: django.contrib.auth.update_session_auth_hash not working after change password
Ruby Thank you very much. Can you tell me what I can do to improve my Django code? I would really appreciate as I'm always open to constructive feedback. I'm still curious why my code successfully changes the password but cannot retain the session afterwards. Thanks for all your help. Chris On Thursday, November 7, 2024 at 6:54:31 PM UTC-6 Ruby wrote: > Hi Chris, > The quality of your code is very poor and needs to be generally improved, > in the meantime, Django already has a built-in "Change Password Form" that > you can use `django.contrib.auth.forms.PasswordChangeForm` ( > https://github.com/django/django/blob/042b381e2e37c0c37b8a8f6cc9947f1a2ebfa0dd/django/contrib/auth/forms.py#L520 > ) > You may consider consulting the official Django documentation to > understand the usage better ( > https://docs.djangoproject.com/en/stable/topics/auth/default/) > > On Thu, Nov 7, 2024 at 11:44 PM cseb...@gmail.com > wrote: > >> Ruby >> >> Thank you very much. I tried adding the request argument to my form >> subclass >> and got this... >> >> AttributeError: 'WSGIRequest' object has no attribute 'get' >> >> I don't understand how/why tweaking my form this way will solve the >> session issue. >> My form only gets the new password from the user. The user password >> is updated outside of the form in the code I recently sent. >> >> Are you suggesting I should change the password in the form somehow such >> as in the clean method? >> >> Chris >> >> On Wednesday, November 6, 2024 at 2:07:57 PM UTC-6 Ruby wrote: >> >>> Your code needs to be refactored, here is the real deal, your >>> ChangePassowrdFrom is missing `request`, it should be as it is below >>> form = grandmas4hire.forms.ChangePasswordForm(request, request.POST) >>> >>> >>> On Wed, Nov 6, 2024 at 8:20 PM cseb...@gmail.com >>> wrote: >>> >>>> Ruby >>>> >>>> Thank you very much. Here is my code... >>>> >>>> >>>> INV= grandmas4hire.models.Invitation >>>> >>>> ... >>>> >>>> def add_url_param(url, param, arg): >>>> >>>> prefix = "&" if "?" in url else "/?" >>>> >>>> >>>> >>>> return url + prefix + f'{param}={str(arg).replace(" ", "+")}' >>>> >>>> >>>> --- >>>> >>>> @django.contrib.auth.decorators.login_required >>>> >>>> def change_password(request): >>>> >>>> user = request.user >>>> >>>> msg = request.GET.get("msg") >>>> >>>> if request.method == "POST": >>>> >>>> form = >>>> grandmas4hire.forms.ChangePasswordForm(request.POST) >>>> if form.is_valid(): >>>> >>>> new_password = >>>> form.cleaned_data["new_password"] >>>> inv = INV.objects.get(user = user) >>>> >>>> inv.user.set_password(new_password) >>>> >>>> inv.user.save() >>>> >>>> >>>> django.contrib.auth.update_session_auth_hash(request, >>>> >>>> user) >>>> url = >>>> add_url_param("/change_password", >>>> "msg", >>>> >>>> >>>> "Password+changed.") >>>> reply= django.shortcuts.redirect(url) >>>>
Re: django.contrib.auth.update_session_auth_hash not working after change password
I wrote it myself. Why? cs On Wednesday, November 6, 2024 at 2:34:02 PM UTC-6 Ken BHHO wrote: > @cseb Where did you get that Django Code? > > On Wed, 6 Nov 2024 at 15:07, Ruby wrote: > >> Your code needs to be refactored, here is the real deal, your >> ChangePassowrdFrom is missing `request`, it should be as it is below >> form = grandmas4hire.forms.ChangePasswordForm(request, request.POST) >> >> >> On Wed, Nov 6, 2024 at 8:20 PM cseb...@gmail.com >> wrote: >> >>> Ruby >>> >>> Thank you very much. Here is my code... >>> >>> >>> INV= grandmas4hire.models.Invitation >>> >>> ... >>> >>> def add_url_param(url, param, arg): >>> >>> prefix = "&" if "?" in url else "/?" >>> >>> >>> >>> return url + prefix + f'{param}={str(arg).replace(" ", "+")}' >>> >>> >>> --- >>> >>> @django.contrib.auth.decorators.login_required >>> >>> def change_password(request): >>> >>> user = request.user >>> >>> msg = request.GET.get("msg") >>> >>> if request.method == "POST": >>> >>> form = >>> grandmas4hire.forms.ChangePasswordForm(request.POST) >>> if form.is_valid(): >>> >>> new_password = form.cleaned_data["new_password"] >>> >>> inv = INV.objects.get(user = user) >>> >>> inv.user.set_password(new_password) >>> >>> inv.user.save() >>> >>> >>> django.contrib.auth.update_session_auth_hash(request, >>> >>> user) >>> url = add_url_param("/change_password", >>> >>> "msg", >>> >>> >>> "Password+changed.") >>> reply= django.shortcuts.redirect(url) >>> >>> else: >>> >>> reply = django.shortcuts.render(request, >>> >>> >>> "change_password.html", >>> {"form" : form}) >>> >>> else: >>> >>> form = grandmas4hire.forms.ChangePasswordForm() >>> >>> reply = django.shortcuts.render(request, >>> >>> "change_password.html", >>> >>> {"form" : form, >>> >>> "msg" : msg}) >>> >>> >>> >>> return reply >>> >>> On Tuesday, November 5, 2024 at 5:41:09 PM UTC-6 Ruby wrote: >>> >>>> How was it implemented? >>>> Show a snippet from your code >>>> See how it was used in my code >>>> >>>> form = ChangePasswordForm(request, request.POST) >>>> if form.is_valid(): >>>> user = form.save() >>>> update_session_auth_hash(request, user) >>>> messages.success( >>>>
Re: django.contrib.auth.update_session_auth_hash not working after change password
Ruby Thank you very much. I tried adding the request argument to my form subclass and got this... AttributeError: 'WSGIRequest' object has no attribute 'get' I don't understand how/why tweaking my form this way will solve the session issue. My form only gets the new password from the user. The user password is updated outside of the form in the code I recently sent. Are you suggesting I should change the password in the form somehow such as in the clean method? Chris On Wednesday, November 6, 2024 at 2:07:57 PM UTC-6 Ruby wrote: > Your code needs to be refactored, here is the real deal, your > ChangePassowrdFrom is missing `request`, it should be as it is below > form = grandmas4hire.forms.ChangePasswordForm(request, request.POST) > > > On Wed, Nov 6, 2024 at 8:20 PM cseb...@gmail.com > wrote: > >> Ruby >> >> Thank you very much. Here is my code... >> >> >> INV= grandmas4hire.models.Invitation >> >> ... >> >> def add_url_param(url, param, arg): >> >> prefix = "&" if "?" in url else "/?" >> >> >> >> return url + prefix + f'{param}={str(arg).replace(" ", "+")}' >> >> >> --- >> >> @django.contrib.auth.decorators.login_required >> >> def change_password(request): >> >> user = request.user >> >> msg = request.GET.get("msg") >> >> if request.method == "POST": >> >> form = >> grandmas4hire.forms.ChangePasswordForm(request.POST) >> if form.is_valid(): >> >> new_password = form.cleaned_data["new_password"] >> >> inv = INV.objects.get(user = user) >> >> inv.user.set_password(new_password) >> >> inv.user.save() >> >> >> django.contrib.auth.update_session_auth_hash(request, >> >> user) >> url = add_url_param("/change_password", >> >> "msg", >> >> "Password+changed.") >> >> reply= django.shortcuts.redirect(url) >> >> else: >> >> reply = django.shortcuts.render(request, >> >> >> "change_password.html", >> {"form" : form}) >> >> else: >> >> form = grandmas4hire.forms.ChangePasswordForm() >> >> reply = django.shortcuts.render(request, >> >> "change_password.html", >> >> {"form" : form, >> >> "msg" : msg}) >> >> >> >> return reply >> >> On Tuesday, November 5, 2024 at 5:41:09 PM UTC-6 Ruby wrote: >> >>> How was it implemented? >>> Show a snippet from your code >>> See how it was used in my code >>> >>> form = ChangePasswordForm(request, request.POST) >>> if form.is_valid(): >>> user = form.save() >>> update_session_auth_hash(request, user) >>> messages.success( >>> request, "Your password h
Re: django.contrib.auth.update_session_auth_hash not working after change password
Ruby Thank you very much. Here is my code... INV= grandmas4hire.models.Invitation ... def add_url_param(url, param, arg): prefix = "&" if "?" in url else "/?" return url + prefix + f'{param}={str(arg).replace(" ", "+")}' --- @django.contrib.auth.decorators.login_required def change_password(request): user = request.user msg = request.GET.get("msg") if request.method == "POST": form = grandmas4hire.forms.ChangePasswordForm(request.POST) if form.is_valid(): new_password = form.cleaned_data["new_password"] inv = INV.objects.get(user = user) inv.user.set_password(new_password) inv.user.save() django.contrib.auth.update_session_auth_hash(request, user) url = add_url_param("/change_password", "msg", "Password+changed.") reply= django.shortcuts.redirect(url) else: reply = django.shortcuts.render(request, "change_password.html", {"form" : form}) else: form = grandmas4hire.forms.ChangePasswordForm() reply = django.shortcuts.render(request, "change_password.html", {"form" : form, "msg" : msg}) return reply On Tuesday, November 5, 2024 at 5:41:09 PM UTC-6 Ruby wrote: > How was it implemented? > Show a snippet from your code > See how it was used in my code > > form = ChangePasswordForm(request, request.POST) > if form.is_valid(): > user = form.save() > update_session_auth_hash(request, user) > messages.success( > request, "Your password has been successfully updated") > return redirect(request.META.get('HTTP_REFERER')) > > On Tue, Nov 5, 2024 at 10:30 PM cseb...@gmail.com > wrote: > >> When I change a password, users are logged out. >> Django recommends keeping users logged in >> by calling django.contrib.auth.update_session_auth_hash(request, user). >> >> This is not working in a Django website of mine. >> They must log in again!? >> >> There are no error messages. Is there any way I can provide >> more details? >> >> Chris >> >> -- >> 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 visit >> https://groups.google.com/d/msgid/django-users/04908d1c-a1e4-41ea-afd8-e227f78af8bcn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/04908d1c-a1e4-41ea-afd8-e227f78af8bcn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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 visit https://groups.google.com/d/msgid/django-users/0c0c2c50-5064-4e9d-a579-f0ddb323c11an%40googlegroups.com.