簡體   English   中英

django-當前路徑…與這些都不匹配

[英]django - The current path … didn't match any of these

http://127.0.0.1:8000/contextual/main/可以運行,但是出於某種原因http://127.0.0.1:8000/contextual/main/create/表示該URL不存在,即使我包含了該URL。 怎么了?

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

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

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

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)

您在主模式之后有一個終止$ ,因此不會再匹配其他字符。 您應該刪除它。

    re_path(r'^main/', include([...]))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM