confusing about running some codes in django

17 views
Skip to first unread message

Vahid Asadi

unread,
Aug 28, 2019, 9:15:20 AM8/28/19
to Django users
Hi . 
when i read the django docs,it suggested that running some code but it does not note that where to write this piece of code . the code is :

from django.contrib.auth.models import User
u = User.objects.get(username='john')
u.set_password('new password')
u.save()

i know that i can run it in django shell (manage.py shell)
but i want to write these in a file(its some confusing that every code in views.py should return a http response but this type of commands does not return any respone) 
where should i put this code ??
thanks for your attention.

Mario R. Osorio

unread,
Aug 29, 2019, 9:24:05 AM8/29/19
to Django users
That code is meant for you to type it in the python console however, you could also include it pretty much anywhere in your code.

Amitesh Sahay

unread,
Aug 29, 2019, 1:53:54 PM8/29/19
to Django users
When you do a CRUD operation , you can use Django ORMs in view.py.

Regards,
Amitesh Sahay


--
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/b6b3b24e-b34e-42e6-b637-3e6a30ca2823%40googlegroups.com
.

Vahid Asadi

unread,
Aug 29, 2019, 3:27:38 PM8/29/19
to Django users
Thanks

Vahid Asadi

unread,
Aug 29, 2019, 3:30:59 PM8/29/19
to django...@googlegroups.com

But when I put this code in model.py, when I run the server it returns an error about constraints failed but the user was added in Django admin users. Why this 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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages