ฉันกำลังเรียนรู้ที่จะพัฒนาใน Django และฉันใช้ PyCharm กับโปรเจ็กต์ของฉัน และฉันต้องการใช้คอนโซล iPython ในนั้น
iPython เปิดตัวแล้ว นี่ไม่ใช่ปัญหา
ปัญหาคือเมื่อฉันเปิด iPython จากคอนโซล โมเดลของฉันและคลาสยูทิลิตี้อื่นๆ ทั้งหมดจะถูกนำเข้า
นี่คือสิ่งที่เกิดขึ้นเมื่อฉันเปิดคำสั่ง python3 manage.py shell_plus
:
# Shell Plus Model Imports
from app.models.models import Model1, Model2, Model3
from django.contrib.admin.models import LogEntry
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.contrib.sessions.models import Session
# Shell Plus Django Imports
from django.core.cache import cache
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import Avg, Case, Count, F, Max, Min, Prefetch, Q, Sum, When, Exists, OuterRef, Subquery
from django.utils import timezone
from django.urls import reverse
/myproject/env/lib/python3.7/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved
warn("IPython History requires SQLite, your history will not be saved")
Python 3.7.4 (default, Jul 23 2019, 18:02:54)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
ในขณะเดียวกันเมื่อฉันเริ่ม Python Console ใน PyCharm ไม่มีการนำเข้าใด ๆ และฉันต้องนำเข้าโมเดลทั้งหมดด้วยตนเอง นี่คือสิ่งที่เกิดขึ้นใน PyCharm Python Console:
/home/user/myproject/env/bin/python /snap/pycharm-community/188/plugins/python-ce/helpers/pydev/pydevconsole.py --mode=client --port=33543
/home/user/myproject/env/lib/python3.7/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved
warn("IPython History requires SQLite, your history will not be saved")
import sys, django
print('Python %s on %s' % (sys.version, sys.platform))
Python 3.7.4 (default, Jul 23 2019, 18:02:54)
Type 'copyright', 'credits' or 'license' for more information
In[2]:
แน่นอนว่าคำสั่งถูกดำเนินการบนคำสั่ง shell_plus ซึ่งไม่ได้อยู่ในคอนโซล PyCharm
และนี่คือเวอร์ชันที่ใช้
Ubuntu = 18.04 LTS
python = 3.7.4
iPython = 7.13.0
Django = 3.0.5
PyCharm = 2019.3.4 Community
ขอบคุณสำหรับความช่วยเหลือของคุณ ฉันสามารถช่วยฉันได้