[英]django - The current path … didn't match any of these
http://127.0.0.1:8000/contextual/main/ works, but for some reason http://127.0.0.1:8000/contextual/main/create/ says the url does not exist, even if I included it. http://127.0.0.1:8000/contextual/main/可以运行,但是出于某种原因http://127.0.0.1:8000/contextual/main/create/表示该URL不存在,即使我包含了该URL。 What's wrong? 怎么了?
urls.py urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import TemplateView
from django.urls import path, re_path, include
urlpatterns = [
#url('admin/', admin.site.urls),
#url(r'^user/', include('base.urls')),
#url(r'^contextual/', include('base.urls')),
#url(r'^home/', TemplateView.as_view(template_name='home.html'), name='home'),
#url(r'^plots/', include('plots.urls')),
# url(r'^welldata/', include('welldata.urls')),
# eric's
path('contextual/', include('eric_base.urls'))
eric_base/urls.py eric_base / urls.py
from django.urls import re_path, include
from eric_base import views as base_views
app_name = 'eric_base'
urlpatterns = [
re_path(r'^main/$', include([
re_path(r'^$', base_views.ContextualMainView.as_view(), name='main'),
re_path(r'^create/$', base_views.WellCreateView.as_view(), name='create'),
])),
]
views.py views.py
from django.shortcuts import render
from django.views.generic import View, TemplateView, ListView, DetailView, CreateView, UpdateView, DeleteView
from . import models
class ContextualMainView(TemplateView):
template_name = 'contextual_main.html'
class WellCreateView(CreateView):
template_name = 'practice_add_well.html'
model = models.WellInfo
fields = '__all__'
models.py models.py
from django.db import models
# Create your models here.
class WellInfo(models.Model):
name = models.CharField(max_length=100)
region_location = models.CharField(max_length=100)
spud_date = models.CharField(max_length=100)
well_bore = models.CharField(max_length=100)
rig_name = models.CharField(max_length=100)
status = models.CharField(max_length=100)
You have a terminating $
after the main pattern, so no further characters will be matched. 您在主模式之后有一个终止$
,因此不会再匹配其他字符。 You should remove that. 您应该删除它。
re_path(r'^main/', include([...]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.