Questions tagged [django-shell]

78 questions
344
votes
27 answers

How to execute a Python script from the Django shell?

I need to execute a Python script from the Django shell. I tried: ./manage.py shell << my_script.py But it didn't work. It was just waiting for me to write something.
user2429940
92
votes
7 answers

How to create user from django shell

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": "", …
shifu
  • 6,586
  • 5
  • 21
  • 21
34
votes
3 answers

Saving image/file through django shell

I am trying to save an image file through django shell. My model.py is: class user(models.Model): name = models.CharField(max_length=20) pic = models.ImageField() Everything is fine with admin and forms but I want to save image using…
26
votes
3 answers

Django: simulate HTTP requests in shell

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…
nemesisdesign
  • 8,159
  • 12
  • 58
  • 97
19
votes
2 answers

Executing a Django Shell Command from the Command Line

I would like to execute a command via Django's manage.py shell function solely from the command line e.g. manage.py shell -c "from myapp import models; print models.MyModel.some_calculation()" the came way you might use the -c option with the…
Cerin
  • 60,957
  • 96
  • 316
  • 522
15
votes
2 answers

Unknown command: shell_plus and --settings

I try to run some python manage.py shell_plus --notebook --settings=my_app.settings.andi But it fails with error: Unknown command: 'shell_plus' Type 'manage.py help' for usage. I have ipython and shell_plus installed (from my pip…
andilabs
  • 22,159
  • 14
  • 114
  • 151
14
votes
1 answer

IPython on Windows - No highlighting or Auto-complete

this has been an issue for a long time for me, but as I mainly develop using Linux I never really cared much about this problem till now. iPython on Windows lacks various features. I really miss color highlighting and auto-completion. Edit: fixed…
RadiantHex
  • 24,907
  • 47
  • 148
  • 244
9
votes
4 answers

How to log production database changes made via the Django shell

I would like to automatically generate some sort of log of all the database changes that are made via the Django shell in the production environment. We use schema and data migration scripts to alter the production database and they are version…
viam0Zah
  • 25,949
  • 8
  • 77
  • 100
8
votes
1 answer

Django Shell API KeyError

I am importing models in django shell API but i get the below error. Here is how it occurs: python manage.py shell from .models import Device I get: File "", line 1, in KeyError: "'__name__' not in globals"
user12510360
8
votes
5 answers

How to run arbitrary code when django shell starts?

This question: Automatically import models on Django shell launch has answers explaining how to import models upon start by using shell_plus, but no answer about how to run code in general. But is there an easy way to just run a python…
fastmultiplication
  • 2,951
  • 1
  • 31
  • 39
5
votes
2 answers

Get all fields of a model in Django Shell

Is it possible to output names of all fields of a specific model in Django Shell? For example, how to get fields from User model: >>> from django.contrib.auth.models import User I know I can get it by accessing models.py of the appropriate app but…
Sayyor Y
  • 1,130
  • 2
  • 14
  • 27
4
votes
2 answers

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

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.
Deonomo
  • 1,583
  • 3
  • 16
  • 25
4
votes
2 answers

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

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…
Simran
  • 593
  • 1
  • 14
  • 37
3
votes
1 answer

Python script not working with django shell

i have written script to create users using csv file. i have to check the sso username is valid or not using an api request as well and its written in _validate_user function. To make the api request i'm using urllib3. Sample code provided…
Ashwin
  • 245
  • 2
  • 7
  • 22
3
votes
1 answer

How to add multiple many to many data in django shell

I have a player instance who played three leagues. in the player model class, I set many to many fields with league class. Now I want to add all 3 leagues to the player instance in Django shell. class League(models.Model): league =…
Mohan
  • 145
  • 2
  • 8
1
2 3 4 5 6