简体   繁体   中英

url issues with django

I can't get my urls to work for django no matter what I try

from django.contrib import admin
from django.urls import include, re_path
from django.conf.urls import url
from catalog import views

urlpatterns = [
    re_path(r'^admin/', admin.site.urls),
    re_path(r'^fruit/?$', views.fruit_catalogue, name='fruit_catalogue'),
    re_path(r'^fruit/?$', views.fruit_details),
    re_path(r'^fruit/(?P<fruit_id>[1-7]{1})/?$', views.fruit_details),
]

There are 2 url.py files that you should check for the correct functioning of the URLs.

First the one, that is in your project, that should look something like this:

from django.contrib import admin
from django.urls import include, path
from django.conf import settings


urlpatterns = [
    path('admin/', admin.site.urls),
    path("", include("NAMEOFAPP.urls")),
] 

and the other is inside your app. and a simple version of it should look something like this:

from django.urls import path

from . import views

urlpatterns = [
    path("home", views.index, name="index"),
    path("login", views.login_view, name="login"),
    path("register", views.register, name="register") 
]

Try to use this same setup and you should be perfectly fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM