gpt4 book ai didi

python - Django:在 INSTALLED_APPS 中定位第四方应用程序的问题

转载 作者:太空宇宙 更新时间:2023-11-04 05:42:23 28 4
gpt4 key购买 nike

当我使用库“ckeditor”运行服务器时,我在 manage.py 文件中遇到了这个错误(我在使用 tinymce 时也遇到了同样的错误):

Traceback (most recent call last):                                                                                                  
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named ckeditor_uploader

在 shell 模式下导入这个库没有问题。我还检查了 shell 中的路径,sys 可以访问安装它的 venv 的“站点包”:

$ python manage.py shell
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from ckeditor.fields import RichTextField
>>>
>>> import sys
>>> for x in sys.path: print x
...
...
/home/ubuntu/workspace/venv/local/lib/python2.7/site-packages
/home/ubuntu/workspace/venv/lib/python2.7/site-packages

我检查了使用 pip list 安装的库列表,其中有“django-ckeditor”。

我的一些文件:

管理.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

设置.py:

INSTALLED_APPS = (
'django.contrib.admin',
...
'myapp',
'ckeditor_uploader',
)
...
CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'Basic',
},
}

点卡住

$ pip freeze
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.8.5
django-ckeditor==5.0.2
django-toolbelt==0.0.1
gunicorn==19.3.0
psycopg2==2.6.1
static3==0.5.1
virtualenv==13.1.2
wheel==0.26.0

网址.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', include('myapp.urls')),
url(r'^ckeditor/', include('ckeditor_uploader.urls') ),
]

我读了一些由旧版本的 pip 引起的类似问题的帖子,但我升级了它。

最佳答案

将您在设置中安装的应用更改为:

设置.py:

INSTALLED_APPS = (
'django.contrib.admin',
...
'myapp',
'ckeditor',
)
...
CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'Basic',
},
}

还记得将 ckeditor 添加到您的 urls.py

urlpatterns = patterns(
'',
...
(r'^ckeditor/', include('ckeditor_uploader.urls')),
...
)

关于python - Django:在 INSTALLED_APPS 中定位第四方应用程序的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33441818/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com