在cpanle(共享主机)上上传文件时,在发布请求后在Django中找不到页面]] << [

问题描述 投票:0回答:2
在本地工作正常,没有错误当我在cpanel(共享主机)上部署django时,一切正常[]

但是当我提交没有图像的表单时,它成功提交了。如果我选择一张图片并提交表格。将得到找不到页面(404)错误

我试图从models.py及其使用过的每个位置禁用imageField。然后我检查了它与imageField的工作正常,不工作

我已使用static_root和url更改了media_root和media_url。但仍然无法正常工作。

models.py

from django.db import models from django.urls import reverse_lazy # Create your models here. class Eventz(models.Model): name = models.CharField(max_length=50) image = models.ImageField(upload_to='events') class Meta: ordering = ['-id'] db_table = 'eventz' def get_absolute_url(self): return reverse_lazy('eventz') def __str__(self): return self.name

  
views.py

from django.shortcuts import render from django.views.generic import CreateView, UpdateView, DeleteView, ListView, TemplateView, RedirectView from .models import Eventz class EventzCreate(CreateView): model = Eventz fields = ['name', 'image'] template_name = 'events.html' def get_context_data(self, **kwargs): context = super(EventzCreate, self).get_context_data(**kwargs) context['events'] = Eventz.objects.all() return context

  
urls.py

from django.contrib import admin from django.urls import path, include from . import settings from django.contrib.staticfiles.urls import static from upload import views from dashboard1.views import EventzCreate urlpatterns = [ path('admin/', admin.site.urls), path('', views.UploadCreate.as_view(), name="upload" ), path('eventz/', EventzCreate.as_view(), name='eventz'), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

  
settings.py

STATIC_URL = '/static/' STATIC_ROOT = '/home/intelexcel/public_html/static' STATIC_URL = '/media/' STATIC_ROOT = '/home/intelexcel/public_html/media' # LOGOUT_REDIRECT_URL = 'login' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]

enter image description here

本地工作正常,当我在cpanel(共享主机)上部署django时,一切正常,但是当我提交没有图像的表单时,它成功提交了。如果我选择...

django image upload cpanel
2个回答
0
投票
您在事件的网址页面上输入的名称是eventz,但在网址栏中显示的模式是event

在您的urls.py中,您应该有类似的内容:


0
投票
使用媒体网址路径更新您的网址列表,如下所示:-
© www.soinside.com 2019 - 2024. All rights reserved.