Django根目录中的urls设置

时间:2019-05-11 05:26:55

标签: django

我正在尝试找出我的错误,但是我无法识别, 给我更好的语法 谢谢

root / urls.py ---->

     from django.conf.urls import url, include
     from django.contrib import admin

       urlpatterns = [
       url(r'^admin/', admin.site.urls),
      url(r'', include('firstapp.urls')),
                    ]

应用程序目录/urls.py

       from django.conf.urls import url

       from . import views


       urlpatterns = [

        url(r'^$', views.home, name = "home"),
        url(r'^productform/>', views.product_create_view, name =                        "productform"),
        url(r'^products/<int:page_id/>', views.products, name = "products"),
         ]

我已经在根目录中完成了我的settings.py

1 个答案:

答案 0 :(得分:0)

您在这里犯错了

url(r'^productform/>', views.product_create_view, name="productform"),
url(r'^products/<int:page_id/>', views.products, name="products"),

尝试一下

from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^$', views.home, name = "home"),
    url(r'^productform/', views.product_create_view, name="productform"),
    url(r'^products/<int:page_id/', views.products, name="products"),
]