Also,
It would be better if you rearrange your patterns.

urlpatterns=[
path('login/', LoginView.as_view(template_name='accounts/login.html'), 
name='login'),
re_path(r'^$',views.home, name='home'),
]

Since your path *r'^$' *matches all request, it is better to keep this at 
end of your list.

On Tuesday, November 13, 2018 at 7:19:22 AM UTC+5:30, Alex Callaway wrote:
>
> In my urlpatterns in the url.py file of my app, I have two pages:
>
> from django.urls import path, re_path
> from django.conf.urls import url
> from . import views
> from django.contrib.auth.views import LoginView
>
> urlpatterns=[
> re_path(r'^$',views.home, name='home'),
> path('login/', LoginView.as_view(template_name='accounts/login.html'), 
> name='login'),
> ]
>
> When I visit : `http://127.0.0.1:8000/home` <http://127.0.0.1:8000/home> 
> I see whats in my `index.html`. 
>
> But when I visit : 
>
> `http://127.0.0.1:8000/accounts/login` 
> <http://127.0.0.1:8000/accounts/login> or 
> `http://127.0.0.1:8000/accounts/login.html` 
> <http://127.0.0.1:8000/accounts/login.html> or 
> `http://127.0.0.1:8000/accounts/login/login` 
> <http://127.0.0.1:8000/accounts/login/login> or 
> `http://127.0.0.1:8000/accounts/login/login/login.html` 
> <http://127.0.0.1:8000/accounts/login/login/login.html> 
>
> I still see what's in my `index.html`. Wtf?
>
>
> Ok. I did say in my views.py I have told it to render `home/index.html` 
> like this :
>
> def home(request):
> return render(request, 'home/index.html')
>
> But I also have this function in views.py as well :
>
>
> def login(request):
> c = {}
> c.update(csrf(request))
> return render(request, 'accounts/login.html', c)
>
> So what's the problem? Why won't it render `accounts/login.html` page when 
> I visit `http://127.0.0.1:8000/accounts/login` 
> <http://127.0.0.1:8000/accounts/login>
>
> By the way, In my main url.py file in the project, I have url patterns 
> this way *(every django project has two urls.py)*:
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('home/', include('clientview.urls')),
> path('accounts/login/', include('clientview.urls')),
> ]
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2622b5d3-8bcd-4277-a94e-1df2a11e8023%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to