django cms apphook - 没有名为 url 的模块错误

发布于 2024-10-28 21:59:55 字数 2232 浏览 7 评论 0原文

我正在学习 django-cms。我尝试制作自定义插件,非常成功,但是当我尝试将自定义插件挂接到 apphook 时,它给了我一个错误,说:

没有名为 url 的模块 。

我遵循 django cms 站点文档中给出的教程,并创建了 cms_app.py 文件。目前,我的应用程序目录包含为 django cms 制作自定义插件所需的所有文件,以及 cms_app.py 的附加文件。

url 设置有问题还是我需要在应用程序目录中创建一个新的 urls.py 文件?

我的 cms_app.py 与教程中给出的完全相同。

编辑 - 1

我使用命令创建了一个名为 myproject 的项目 -

python django-admin.py startproject 我的项目

在参考了 cms 的教程后,我使用基本命令创建了一个名为first的插件

首先使用 python manage.py startapp

现在插件工作得很好,尝试 apphook 之前的目录结构是,

first/
    __init__.py
    cms_plugins.py
    models.py
    tests.py
    views.py

现在尝试在 apphook 中挂接应用程序后,目录结构是:

first/
    __init__.py
    cms_app.py
    cms_plugins.py
    models.py
    tests.py
    views.py

我的 cms_app.py 是如下:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _

class FirstApp(CMSApp):
    name = _("First App") # give your app a name, this is required
    urls = ["first.urls"] # link your app to url configuration(s)

apphook_pool.register(FirstApp) # register your app

我在 myproject 文件夹中有一个 urls.py 文件,如下所示:

from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings


# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'myproject.views.home', name='home'),
    # url(r'^myproject/', include('myproject.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
        url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('cms.urls')),

)

if settings.DEBUG:
    urlpatterns = patterns('',
        (r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
    ) + urlpatterns

我已按照教程中提到的方式重新启动服务器,但没有成功。 关于我的简单应用程序有什么问题有什么想法吗?!

I am learning django-cms. I tried to make custom plugin which was quite successful but when I tried to hook my custom made plugin to apphook, its giving me an error, saying,

No Module named urls
.

I followed the tutorial which was given in django cms sites documentation, and created the cms_app.py file. Currently my application directory has all the files which is required to make a custom plugin for django cms, and an additional file of cms_app.py.

Is something wrong with setting of the url or do I need to create a new urls.py file inside my app directory?

My cms_app.py is exactly the same as given in the tutorial.

EDIT - 1

i have created a project called myproject using command -

python django-admin.py startproject
myproject

After referring to the tutorial given for cms I created a plugin called first, using the basic command

python manage.py startapp first

Now the plugin is working perfectly well, and the directory structure before making an attempt to the apphook was,

first/
    __init__.py
    cms_plugins.py
    models.py
    tests.py
    views.py

Now after making an attempt to hook the app in apphook, the directory structure is:

first/
    __init__.py
    cms_app.py
    cms_plugins.py
    models.py
    tests.py
    views.py

My cms_app.py is as follows:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _

class FirstApp(CMSApp):
    name = _("First App") # give your app a name, this is required
    urls = ["first.urls"] # link your app to url configuration(s)

apphook_pool.register(FirstApp) # register your app

i have a urls.py file in myproject folder, and it is as follows:

from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings


# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^

I have restarted the server as was mentioned in the tutorial, but no success.
Any ideas as to what is wrong with my simple app?!

, 'myproject.views.home', name='home'), # url(r'^myproject/', include('myproject.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), url(r'^', include('cms.urls')), ) if settings.DEBUG: urlpatterns = patterns('', (r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')), ) + urlpatterns

I have restarted the server as was mentioned in the tutorial, but no success.
Any ideas as to what is wrong with my simple app?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乱世争霸 2024-11-04 21:59:55

您指定的 urls 模块是否存在并且位于您的 Python 路径中?您附加到 apphook 的 url 必须存在,然后您才能使用该 apphook,并且该模块必须可导入。

将您的代码粘贴到某处将有助于我们为您提供帮助。

Does the urls module you specify exist and is it in your Python path? The urls you attach to apphooks must exist before you can use that apphook and the module must be importable.

Pasting your code somewhere would help us help you.

烟酒忠诚 2024-11-04 21:59:55

我猜你正在做这个教程:

http://docs .django-cms.org/en/2.1.3/getting_started/tutorial.html

我还没有得到这个项目的最新信息,但我知道你必须执行以下步骤:

http://docs.django-cms.org/en/2.1.3 /getting_started/tutorial.html#url-configuration

编辑

您实际上需要在“first”文件夹下创建 urls.py 文件...并且您需要一个带有 urls 的 cms 模块.py 文件。

编辑2

我的基本文件夹结构看起来像

src/
    cms/
    __ init__.py
    manage.py
    urls.py
    views.py

I'm guessing you are doing this tutorial:

http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html

i haven't got the latest of this project but i know you have to do something like this step:

http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html#url-configuration

EDIT

you need to actually make the urls.py file under the "first" folder ... and you need a cms module with a urls.py file.

EDIT 2

my base folder structure look something like

src/
    cms/
    __ init__.py
    manage.py
    urls.py
    views.py
奈何桥上唱咆哮 2024-11-04 21:59:55

听起来很奇怪,但是错误说 'No module named ...' 通常意味着你有循环导入,所以基本上你试图导入同一个模块两次

Sounds weird, but the error saying 'No module named ...' usually means you have circular import, so basically you're trying to import the same module twice

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文