Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Beginner Problem: I don`t get my view working [RSS Feed]

#1 Dec. 15, 2010 15:06:14

j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Beginner Problem: I don`t get my view working


Hallo,

I don`t know what is wrong with my code, but I can not call a view in
the urls.py of my site:

I have an application hspoints. In the folder is a views.py. In will
post a view files:


settings.py of my Site:

(...)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'hspoints'
)
(...)


view.py of my application hspoints:

from django.http import HttpResponse

def index(request):
return HttpResponse("Hello, world. You're at the index.")


urls.py of my Site:

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
(r'^hspoints/$', include(hspoints.views.index)),
(r'^admin/', include(admin.site.urls)),
)


When i start the testserver withhttp://127.0.0.1:8000/hspoints/I
get:

NameError at /hspoints/

name 'hspoints' is not defined


When I add import hspoints to the urls.py of my site, what I did not
have to do in the poll tutorial, I get:

AttributeError at /hspoints/

'module' object has no attribute 'views'



What am I do wrong? I just don`t get what I forgot to do...

Info: I`m working with PyDev in Eclipse.

Thank you!




--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 15, 2010 16:18:28

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Beginner Problem: I don`t get my view working


On 15 déc, 16:05, josch <joschw...@web.de> wrote:
> Hallo,
>
> I don`t know what is wrong with my code, but I can not call a view in
> the urls.py of my site:
>
> I have an application hspoints. In the folder is a views.py. In will
> post a view files:
>
> urls.py of my Site:
>
> from django.conf.urls.defaults import *
>
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     (r'^hspoints/$', include(hspoints.views.index)),

include() is meant to include an app's urls.py module, not to map a
pattern to a view.

>     (r'^admin/', include(admin.site.urls)),
> )
>
> When i start the testserver withhttp://127.0.0.1:8000/hspoints/I> get:
>
> NameError at /hspoints/
>
> name 'hspoints' is not defined

Indeed.

> When I add import hspoints to the urls.py of my site, what I did not
> have to do in the poll tutorial

Re-read the tutorial more carefully... and then the FineManual's
section about views and urls ;)


The common idiom is to have app-specific urls defined in the app's
urls.py module, then include this urls.py module from the project's
root urls.py, ie:

# hspoints/urls.py

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

urlpatterns = patterns('',
(r'^/$', views.index),
# your other app-specific url patterns here
)


# urls.py

urlpatterns = patterns('',
(r'^hspoints/$', include("hspoints.urls")),
(r'^admin/', include(admin.site.urls)),
)


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Beginner Problem: I don`t get my view working [RSS Feed]

Board footer

Moderator control

Enjoy the 19th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support