Django - Url patatterns dose not work

Clash Royale CLAN TAG#URR8PPP
Django - Url patatterns dose not work
I started working with Django yesterday and I have a little error. I searched on the internet but I cant find the answer for my problem. I made the main app and then I make a little app and tried to link it to the main. Here is my code
urls.py
from django.contrib import admin
from django.urls import path, include
ulrpatterns = [
path('admin/', admin.site.urls),
path('^$', include('personal.urls'));
]
in my personal.urls I have
from django.urls import path, include
from . import views
ulrpatterns = [
path('^$', views.index, name="index");
]
and in views.index I have
def index(request):
return render(request, 'personal/home.html')
Any help would be awesome, thank you!!!
r'^/$'
@Derek朕會功夫 I changed in both urls.py files and still same error
– Horatiu123456
7 mins ago
Use
path_re, path does not work with regexes.– Willem Van Onsem
7 mins ago
path_re
path
Or better, use
path('', ..). OP's version wouldn't work even with re_path, because it terminates the including regex.– Daniel Roseman
4 mins ago
path('', ..)
re_path
Yea, it work with path('', ...), thank you @DanielRoseman
– Horatiu123456
1 min ago
1 Answer
1
You are using the wrong tool here: since django-2.0, there are basically two ways to specify a URL:
path_re
path
Here you somehow mixed the two, and use path(..) function for a "regex-specified" URL.
path(..)
Using path for path pattern-based URLs
path
We can also fix it by using path_re instead:
path_re
# urls.py
from django.contrib import admin
from django.urls import path, include
ulrpatterns = [
path('admin/', admin.site.urls),
path('', include('personal.urls'));
]
and:
# personal/urls.py
from django.urls import path, include
from . import views
ulrpatterns = [
path('', views.index, name="index");
]
Using path_re for regular expression-based URLs
path_re
We can also fix it by using path_re instead:
path_re
# urls.py
from django.contrib import admin
from django.urls import path_re, include
ulrpatterns = [
path_re('admin/', admin.site.urls),
path_re('^$', include('personal.urls'));
]
and:
# personal/urls.py
from django.urls import path_re, include
from . import views
ulrpatterns = [
path_re('^$', views.index, name="index");
]
yeah, it work using first method, thank you
– Horatiu123456
39 secs ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try
r'^/$'instead.– Derek 朕會功夫
14 mins ago