B
B
blazer-052015-01-06 20:30:37
Django
blazer-05, 2015-01-06 20:30:37

Pycharm shell how to load Django?

When executing a command in shell

>>> from info.models import MysiteInfo
>>> mm = MysiteInfo.objects.get(id=3)

I get an error without even typing print mm
raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.

If done like this:
>>> import django
>>> django.setup()
>>> from django.db import connection
>>> mm = MysiteInfo.objects.get(id=3)
>>> print mm
Запись 3

That all works. But when writing a function and outputting it, I get an error in the browser. As I understand it, the django module is not loaded in my shell. Where do you need to write these two lines of code so as not to enter them every time before the commands?
import django
django.setup()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oscar Django, 2015-01-06
@blazer-05

File>Settings>Build, Execution, Deployment>Console>Django Console. What to do there I think you will understand. Of course, if I correctly understood the essence of the question. This is for pycharm 4.0
File>Settings>Project Settings>Console>Django Console. This is for pycharm 3.4

B
blazer-05, 2015-01-07
@blazer-05

winordie
Thank you so much for the hint, I corrected the error. In the manage.py file, I connected pymysql there, after uninstalling this module, I removed this code from manage.py

import pymysql
pymysql.install_as_MySQLdb()

and everything worked! Thanks again!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question