16👍
You probably need to change
from mysite import hello
to something like
from mysite.hello_file import hello_view
And then use:
('^test/$',hello_view)
Because you need to pass a (view) function, not a file or module. As I think mgalgs was trying to explain, but I think a bit unclear for beginners.
5👍
I got this error when adding a Class Based View the following way:
url(r'^tv/$', views.MyTemplateView(), name='my_tv'),
of course .as_view()
should be added to fix error object has no attribute 'rindex'
:
url(r'^tv/$', views.MyTemplateView.as_view(), name='my_tv'),
- Django nginx Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
- How to add anchor to django url in template
- IPython doesn't work in Django shell
- Calculate point based on distance and direction
- Does a library to prevent duplicate form submissions exist for django?
4👍
The url pattern should be tuples of strings, not a module. Something like:
urlpatterns = patterns('',
('^test/$','hello.views.hello'),
)
EDIT: You can also pass a callable to patterns. I simply had never seen it done that way before (the docs always pass a string). However, you’re actually passing a module, not a string or a callable (so django gets confused and first treats it like it must be a callable since it’s not a string but then goes back to trying to treat it like a string, hence the call to rindex
). Maybe you meant to pass hello.views.hello
like so:
urlpatterns = patterns('',
('^test/$',hello.views.hello),
)
Alternatively, you could change your import line to from mysite.hello.views import hello
, or just use the string syntax (I believe 'hello.views.hello'
would do it as initially suggested).
- Using Django's built in web server in a production environment
- How to return data with 403 error in Django Rest Framework?
- Make Django test case database visible to Celery
- Django database delete specific number of entries
- How can I use AWS's Dynamo Db with Django?
- How can I best find out how django works internally?
- Django admin many-to-many intermediary models using through= and filter_horizontal