我在學習django-cms。我試圖使這是相當成功的自定義插件,但是當我試圖鉤我的定製插件來apphook,它給我的錯誤,他說,django cms apphook錯誤
No Module named urls .
我跟着這是在Django的CMS網站文檔給出的教程,並創建了cms_app.py文件。目前,我的應用程序目錄包含爲django cms創建自定義插件所需的所有文件,以及一個額外的cms_app.py文件。
設置網址時出現錯誤或者我需要在我的應用目錄中創建一個新的urls.py文件?
我的cms_app.py與教程中給出的完全相同。
我已創建使用命令調用MyProject的項目 -
python django-admin.py startproject myproject
指爲CMS提供的教程後,我創建了第一個叫的插件,使用基本的命令
python manage.py startapp first
現在插件工作完好,並且在嘗試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
我已重新啓動服務器,如教程中所述,但沒有成功。 任何有關我的簡單應用程序出現問題的想法?
編輯 - 1 我的意見文件如下:
from django.http import HttpResponse
def index(request):
「」」Generate the context for the main summary page」」」
return render_to_response(‘first/first.html’)
編輯 - 2 我已經改變了我的第一個應用程序文件夾內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'^first/$', include('first.views.index')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
但現在我得到這個錯誤:
SyntaxError at/
Non-ASCII character '\xe2' in file /home/naveen/django_projects/myproject/first/views.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 4)
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: SyntaxError
Exception Value:
Non-ASCII character '\xe2' in file /home/naveen/django_projects/myproject/first/views.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 4)
Exception Location: /usr/local/lib/python2.6/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/local/lib/python2.6/dist-packages',
'/usr/local/lib/python2.6/dist-packages/django_evolution-0.6.2-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Thu, 31 Mar 2011 11:00:41 -0500
我編輯了網址和瀏覽量,但現在我收到了這個錯誤。
NameError at /first/
global name 'render_to_response' is not defined
Request Method: GET
Request URL: http://localhost:8000/first/?preview
Django Version: 1.3
Exception Type: NameError
Exception Value:
global name 'render_to_response' is not defined
Exception Location: /home/naveen/django_projects/myproject/first/views.py in index, line 5
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/local/lib/python2.6/dist-packages',
'/usr/local/lib/python2.6/dist-packages/django_evolution-0.6.2-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Thu, 31 Mar 2011 14:50:32 -0500
感謝回答,你能告訴我是什麼網址模式應該在那裏?!對不起,我現在很困惑。 – Maverick 2011-03-31 13:18:42
因爲我需要了解更多關於您的應用程序中的意見。 – ojii 2011-03-31 13:39:37
現在我的視圖文件中沒有任何內容。它是空的。 – Maverick 2011-03-31 13:44:44