Opened 7 years ago
Closed 7 years ago
#29842 closed Uncategorized (worksforme)
For some reason self.client.get("/") return a Resolve404 error even with the LocaleMiddleware
| Reported by: | Rémy Hubscher | Owned by: | nobody |
|---|---|---|---|
| Component: | Uncategorized | Version: | 2.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
This tests fails:
class LocaleMiddlewareTest(TestCase):
def test_locale_middleware_redirects_to_localized_url(self):
resp = self.client.get("/")
self.assertRedirects(resp, "/fr/")
While this one uses the LocaleMiddleware:
class LocaleMiddlewareTest(TestCase):
def test_locale_middleware_redirects_to_localized_url(self):
resp = self.client.get("/home")
self.assertRedirects(resp, "/fr/home")
Change History (3)
comment:1 by , 7 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 7 years ago
| Resolution: | invalid |
|---|---|
| Status: | closed → new |
You are too quick for me, I didn't had time to elaborate.
Initially I thought this was a bug with the Django Test Client so I landed the code but it also happened in real life.
I was planning to create a pull-request with a failing test but you closed the issue too quickly and since a pull-request need to be linked to an issue I created the issue first.
The minimum setup to reproduce is to use the LocaleMiddleware with the following urls.py file.
urlpatterns = [
path("admin/", admin.site.urls),
]
urlpatterns += i18n_patterns(
path("", views.index, name="index"),
)
comment:3 by , 7 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
Ok I build an app from scratch with Django master and I tried to reproduce without success so far.
from django.conf.urls import url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.http import HttpResponse, Http404
from django.urls import path
def index(request):
return HttpResponse("ok")
def handle_url(request, wordpress_url):
raise Http404("No mapping found for {}".format(wordpress_url))
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
urlpatterns += i18n_patterns(
path("", index, name="index"),
)
urlpatterns += [path("<path:wordpress_url>", handle_url)]
You haven't given any details about how we can reproduce the issue. Please use TicketClosingReasons/UseSupportChannels until you confirm a bug in Django.