django-shell

How to create user from django shell

可紊 提交于 2021-01-20 14:17:07
问题 When i create user from django-admin user password's are encrypted . but when i create user from django shell user-pasword is saved in plain text . Example : { "date_joined": "2013-08-28T04:22:56.322185", "email": "", "first_name": "", "id": 5, "is_active": true, "is_staff": false, "is_superuser": false, "last_login": "2013-08-28T04:22:56.322134", "last_name": "", "password": "pbkdf2_sha256$10000$iGKbck9CED0b$6hWrKYiMPNGKhcfPVGal2YP4LkuP3Qwem+2ydswWACk=", "resource_uri": "/api/v1/user/5/",

How to create user from django shell

放肆的年华 提交于 2021-01-20 14:14:09
问题 When i create user from django-admin user password's are encrypted . but when i create user from django shell user-pasword is saved in plain text . Example : { "date_joined": "2013-08-28T04:22:56.322185", "email": "", "first_name": "", "id": 5, "is_active": true, "is_staff": false, "is_superuser": false, "last_login": "2013-08-28T04:22:56.322134", "last_name": "", "password": "pbkdf2_sha256$10000$iGKbck9CED0b$6hWrKYiMPNGKhcfPVGal2YP4LkuP3Qwem+2ydswWACk=", "resource_uri": "/api/v1/user/5/",

Django: simulate HTTP requests in shell

冷暖自知 提交于 2019-12-31 12:22:26
问题 I just learnt that with Rails is possible to simulate HTTP requests in the console with few lines of code. Check out: http://37signals.com/svn/posts/3176-three-quick-rails-console-tips (section "Dive into your app"). Is there a similar way to do that with Django? Would be handy. 回答1: How I simulate requests from the python command line is: Use the excellent requests library Use the django reverse function A simple way of simulating requests is: >>> from django.urls import reverse >>> import

Django: simulate HTTP requests in shell

半腔热情 提交于 2019-12-31 12:22:05
问题 I just learnt that with Rails is possible to simulate HTTP requests in the console with few lines of code. Check out: http://37signals.com/svn/posts/3176-three-quick-rails-console-tips (section "Dive into your app"). Is there a similar way to do that with Django? Would be handy. 回答1: How I simulate requests from the python command line is: Use the excellent requests library Use the django reverse function A simple way of simulating requests is: >>> from django.urls import reverse >>> import

Variables scope in inline django shell, vs python shell

纵饮孤独 提交于 2019-12-22 10:04:14
问题 I have problem, with strange behavior of django shell. I have this code: fields = ('name', 'description', 'long_description', 'foot_description') a = 1 dict( (field, a) for field in fields) When I run it from python shell it's give me right dict. But when i running it from django shell i get: --------------------------------------------------------------------------- NameError Traceback (most recent call last) /usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in

Django difficulty in displaying the data(count)

拟墨画扇 提交于 2019-12-12 02:45:59
问题 Im new to django and trying to learn with building a forum my model class Subject(models.Model): name=models.CharField(max_length=128) created=models.DateTimeField('Created Date') def __str__(self): return self.name class Book(models.Model): book_subject=models.ForeignKey(Subject,on_delete=models.CASCADE) book_title=models.CharField(max_length=128) url=models.URLField() votes=models.IntegerField(default=0) def __str__(self): return self.book_title my query to database in django shell Subject

Change Primary Key field to unique field

耗尽温柔 提交于 2019-12-11 18:04:52
问题 When setting up my database structure, I was stupid enough to set a field called "student_id" as "primary_key=True" for my Student class. I only realised much later that there are (rare) occasions where it is necessary to change said "student_id". When doing that via a form, Django will automatically duplicate the student, which is not what I want. I would like to change "primary_key=True" to "unique=True", and am wondering how to do that. My current plan is to add a field called "id" to the

Delete all django.contrib.messages

余生长醉 提交于 2019-12-11 08:15:35
问题 I recently realized that a module in our Django web app was using django.contrib.messages. However, the template's context processor did not have the django.contrib.messages.context_processors.messages processor added. I'm worried that when I push this to production, users will see all their old messages for all pages that had generated them. Is there a way to clear these messages for all users from the django shell ? 回答1: Messages will be shown for those users whose sessions already contain

django.db.utils.OperationalError: foreign key mismatch in Shell command forloop

风流意气都作罢 提交于 2019-12-08 12:19:01
问题 I am working on the following two Django models: Organisation model which has the User as Foreign key and the Category list which has the Organisation as its Foreign Key. Following are the Models : # Create your models here. from django.contrib.auth.models import User from django.db import models class Organisation(models.Model): user = models.ForeignKey( User, on_delete=models.CASCADE, null=True ) organisation_name = models.TextField( primary_key=True, blank=True ) def __str__(self): return

How can I print the value of TEMPLATE_DIRS from the django interactive shell?

一个人想着一个人 提交于 2019-12-07 11:54:18
问题 I would like to print this value for debugging purposes. How can I do it? print TEMPLATE_DIRS doesn't work print settings.TEMPLATE_DIRS doesn't work. 回答1: Did you import the settings first? $steve ./manage.py shell Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) In [1]: from django.conf import settings In [2]: settings.TEMPLATE_DIRS Out [2] ('/Volumes/HDD/usr/local/django/mytestproject/templates',) 回答2: I think the easiest, and therefore the ans you may be looking for is to add the following