You've chosen the wrong answer on the page you linked to. You can't use the redirect
shortcut in your URL patterns, since it is not a view. Using RedirectView
is the correct approach.
error in URLconf in django - improperly configured
-
29-06-2023 - |
質問
I want to redirect to my app URL from project url for homepage which is r'^$'
.
I followed this link. but it did not help.
This is the urls.py
of my project:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', redirect('home')),
url(r'^link/', include('link_app.urls')),
)
This is the urls.py
of my app link:
urlpatterns=patterns('',
url(r'^$', LinkListView.as_view(), name='home'),
)
so basically I am aiming at
http://127.0.0.1:8000/
and http://127.0.0.1:8000/link/
to be processed by the same view.
I get the following error:
ImproperlyConfigured at /
The included urlconf link_project.urls doesn't have any patterns in it
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.6
Exception Type: ImproperlyConfigured
Exception Value:
The included urlconf link_project.urls doesn't have any patterns in it
解決 2
他のヒント
Change your projects urls.py file to modify the
from django.core.urlresolvers import reverse_lazy
from django.views.generic import RedirectView
urlpatterns = patterns('',
url(r'^/$',RedirectView.as_view(url=reverse_lazy('home'))),
url(r'^link/$', LinkedListView.as_view(), name='home'),
The solution assumes that your link app has only one url, for multiple urls in your app try adding a name attribute to url(r'^link/$')
If the view which you want to process your urls is the one inside link_app
, then do the following:
urls.py of your project:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('link_app.urls')),
)
urls.py of your link_app
:
urlpatterns=patterns('',
url(r'/$', LinkListView.as_view(), name='home'),
url(r'link/$', LinkListView.as_view(), name='home_link'),
)
Let me know if this worked for you
Just include your link_app.urls
immediately after the admin urls with regex r'^'
.
Then use the following patterns within link_app.urls
to call the same view:
urlpatterns=patterns('',
url(r'^$', LinkListView.as_view(), name='home'),
url(r'^link/$', LinkListView.as_view(), name='link'),
)