开发者

django cms apphook error

开发者 https://www.devze.com 2023-02-21 05:49 出处:网络
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,

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.

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'^$', '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?!

EDIT - 1 My views file is as follows:

from django.http import HttpResponse

def index(request):
    “””Generate the context for the main summary page”””
    return render_to_response(‘first/first.html’)

Edit - 2 I have changed my urls.py inside first app folder to this :

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

But now I am getting this error:

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
开发者_如何学JAVA

I have edited the urls and views but now I am getting this error.

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


You do not have a first.urls module with the URLs of your 'first' app. Next to your file first/models.py, create a file first/urls.py which contains the URL patterns for the 'first' app.

For the views you give in your questions, the urls.py should look something like this:

from django.conf.urls.defaults import *
from first.views import index

urlpatterns = patterns('',
    url(r'^$', index),
)

Also note that in your views, you use non-standard quote characters, it should look like this:

from django.http import HttpResponse

def index(request):
    """Generate the context for the main summary page"""
    return render_to_response("first/first.html")
0

精彩评论

暂无评论...
验证码 换一张
取 消