"No module named simple" error in Django

ImportError at / No module named simple Django Version: 1.5.dev20120710212642 

I installed the latest version of django. I use

 from django.views.generic.simple import redirect_to 

in my urls.py. What's wrong? Is it out of date?

+61
django
Jul 11 '12 at 8:20
source share
4 answers

Use class representations instead of redirect_to , as these function-based generic representations are deprecated.

Here is a simple example of using class based views

 from django.conf.urls import patterns, url, include from django.views.generic import TemplateView urlpatterns = patterns('', (r'^about/', TemplateView.as_view(template_name="about.html")), ) 

Update

If someone wants to redirect the url, use RedirectView .

 from django.views.generic import RedirectView urlpatterns = patterns('', (r'^one/$', RedirectView.as_view(url='/another/')), ) 
+125
Jul 11 2018-12-12T00:
source share

it should work

 from django.conf.urls import patterns from django.views.generic import RedirectView urlpatterns = patterns('', url(r'some-url', RedirectView.as_view(url='/another-url/')) ) 
+52
Dec 20
source share

Yes, the old standard function-based views were deprecated in 1.4. Use class representations instead.

+5
Jul 11 '12 at 8:25
source share

And for the record (without the corresponding example currently in the documentation) use RedirectView with parameters:

 from django.conf.urls import patterns, url from django.views.generic import RedirectView urlpatterns = patterns('', url(r'^myurl/(?P<my_id>\d+)$', RedirectView.as_view(url='/another_url/%(my_id)s/')), ) 

Note that although the regular expression searches for a number ( \d+ ), the parameter is passed as a string ( %(my_id)s ).

What is still unclear how to use RedirectView with template_name in urls.py

+2
Feb 12 '15 at 10:50
source share



All Articles