找不到Django 404页面错误http:// localhost:8000 / static / feed.html

问题描述 投票:0回答:1

django正在将/ static /网址添加到我的路径中,但我不知道为什么

这是我的views.py

from django.shortcuts import render
from django.views.generic import TemplateView, ListView, CreateView
from app.models import SendSMS
from app.forms import SendSMSForm
from django.urls import reverse_lazy
from app.utils import send_twilio_message
from django.conf import settings 
import datetime
# Create your views here.

# Create your models here.

def index(request): 
     return render(request, 'index.html')
def feed(request): 
     return render(request, 'feed.html')
def upload(request): 
     return render(request, 'upload.html')
def messages(request): 
    return render(request, 'messages.html')
def statistics(request): 
    return render(request, 'statistics.html')


class SendSmsCreateView(CreateView):
     model = SendSMS
     form_class = SendSMSForm
     template_name = 'messages.html'
     success_url = reverse_lazy('send_sms')

     def form_valid(self, form):
         number = form.cleaned_data['to_number']
         body = form.cleaned_data['body']
        # call twilio
         sent = send_twilio_message(number, body)
        # save form
        send_sms = form.save(commit=False)
        send_sms.from_number = settings.TWILIO_PHONE_NUMBER
        send_sms.sms_sid = sent.sid
        send_sms.account_sid = sent.account_sid
        send_sms.status = sent.status
        send_sms.sent_at = datetime.datetime.now()
        if sent.price:
            send_sms.price_unit = sent.price_unit
            send_sms.save()

        return super(SendSmsCreateView, self).form_valid(form)      

这是我的应用urls.py

from . import views
from django.contrib import admin
from django.conf.urls import url
from django.urls import path, include
app_name = 'app'

urlpatterns = [
   path('', views.index, name='index'),
   path('', views.feed, name='feed'),
   path('', views.upload, name='upload'),
   path('', views.messages, name='messages'),
   path('', views.statistics, name='statistics'),
]

这是我的项目urls.py

from django.contrib import admin
from django.conf.urls import url
from django.urls import path, include
from app.views import SendSmsCreateView
url(r'^admin/', admin.site.urls),
# ... your url patterns
path('', include('app.urls', namespace='app')),


url(
    regex=r'^app/$',
    view=SendSmsCreateView.as_view(),
    name='send_sms'
  ),

]

这是我的index.html文件

{% load static %}

<!DOCTYPE html>
 <html>
<head>
</head>
<body>
<li class="nav-item">
        <a href=" {% static 'feed.html' %} " class="nav-link">
          <i class="nav-icon fas fa-th"></i>
          <p>
            Feed
            <span class="right badge badge-danger">New</span>
          </p>
        </a>
      </li>
      <li class="nav-item has-treeview">
        <a href=" {% static 'messages.html' %} " class="nav-link">
          <i class="nav-icon fas fa-copy"></i>
          <p>
            Compose Message

          </p>
        </a>

      </li>
      <li class="nav-item has-treeview">
        <a href=" {% static 'upoad.html' %} " class="nav-link">
          <i class="nav-icon fas fa-chart-pie"></i>
          <p>
            Upload CSV
          </p>
        </a>
      </li>

   </body>
python mysql django url azure-web-app-service
1个回答
0
投票

一些值得注意的错误是>

视图中缺少上下文,如图所示添加空括号

def index(request): 
     return render(request, 'index.html', {})

索引URL中的错误,需要添加非重叠的正则表达式模式

path('', views.index, name='index'),
path('feed/', views.feed, name='feed'),
path('upload/', views.upload, name='upload'),
path('messages/', views.messages, name='messages'),
path('statistics/', views.statistics, name='statistics'),

将URL更改为过期的路径

path('app/',
    view=SendSmsCreateView.as_view(),
    name='send_sms'
  ),
© www.soinside.com 2019 - 2024. All rights reserved.