我正在使用Django 2.0开发网站,但有一个奇怪的(烦人的)问题在开发环境中不存在。
我在myweb.com/admin上,保存数据,并且它具有ImageField,保存时Django告诉我:
Page not found (404)
Request Method: POST
Request URL: http://www.myweb.com/admin/about/about/add/
Raised by: django.contrib.admin.options.add_view
Using the URLconf defined in myweb.urls, Django tried these URL patterns, in this order:
busqueda/
contacto/
sobre-mi/
admin/
[name='home']
<slug:categoria>/ [name='category']
<slug:category>/<slug:slug>/ [name='post']
^media\/(?P<path>.*)$
The current path, about/about/add/, didn't match any of these.
我之所以提到ImageField是因为没有该Field的两个模型都没有问题。
这是myproject / urls.py:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('busqueda/', include('search.urls')),
path('contacto/', include('contact.urls')),
path('sobre-mi/', include('about.urls')),
path('admin/', admin.site.urls),
path('', include('post.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
关于/urls.py:
from django.urls import path
from .views import AboutView
app_name = 'about'
urlpatterns = [
path('', AboutView.as_view(), name='about-me'),
]
我无法自己解决此问题。
编辑:关于/admin.py
from django.contrib import admin
from .models import About
# Register your models here.
class AboutAdmin(admin.ModelAdmin):
readonly_fields = ('created', 'updated')
# Inyectamos nuestro fichero css
class Media:
css = {
'all': ('core/css/custom_ckeditor.css',)
}
admin.site.register(About, AboutAdmin)
编辑2 :我已经从模型中删除了图像字段,并且正确保存了
答案 0 :(得分:0)
已解决,问题是我的托管公司为我提供的Python版本。他们只有python 3.4,但是Django的版本需要更少的python 3.5。我在另一家企业尝试过,效果很好。