I have a problem with my URL redirection of localhost. Everytime I open localhost:8000, I get a redirect to http://localhost:8000/^catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/catalog/
This is weird, as this is my code:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
# Use include() to add paths from the catalog application
from django.urls import include
urlpatterns += [
path('home/', include('home.urls')),
]
#Add URL maps to redirect the base URL to our application
from django.views.generic import RedirectView
urlpatterns += [
path('', RedirectView.as_view(url='home/', permanent=True)),
]
# Use static() to add url mapping to serve static files during development (only)
from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
It should redirect to localhost:8000/home/ If I’m not mistaken. I have no idea where the /catalog/ came from as well in this case
Hopefully someone can help
Hi @calvinlancel
You posted this already at Redirectview error . What’s changed since?
Also I edited your code to be highlighted. Please do that in future.
Thanks,
Adam
Nothing changed unfortunately, only I changed the url() method to a path method with a newer django and python version… Thought that would solve the problem
If I type in localhost:8000/home/ then the link works, but it does not redirect to /home/ with nothing behind it: localhost:8000 directs to the catalog repetition one…
What are the contents of your home.urls file?
from django.urls import path
from . import views
urlpatterns = [
]
Only this, so that does not change it…
So the only other place where you’re setting urlpatterns is:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
What are the values in those two settings?
STATIC_URL = ‘/static/’
I think that there is maybe a way that the localhost:8000 url is changed by something different than this Django application, but I have no idea what or where it is
Are you running this locally under runserver? If not, how are you running it?
(I agree, somewhere your app is finding the string “catalog” to be added into URLs, it’s just a question of finding it.)
Also: did you check in a “private mode” tab on your browser? Sometimes browsers cache permanent redirects no matter how many times you try visit them. Using a private tab avoids that cache.
This actually works, but still it is supposed to work with a normal browser, isn’t it?
You know how to fix those browsers cache permanent redirects?
Yes locally under runserver …
So what you may need to do is clear the cache for your browser for localhost.
No clue how to do that, but I will try