我在虚拟服务器上托管的django项目有这些设置,但不是Heroku等。我需要一些帮助,因为看起来该工具无法找到我在创建博客帖子时保存的图片。我按照文档中的正确步骤进行操作,但仍无法找到问题所在。
我的设置是:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "static_root")
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static_in_pro", "our_static"),)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_in_env", "media_root")
我的帖子创建
def posts_create(request):
# if not request.user.is_superuser:
# raise Http404
if not request.user.is_staff or not request.user.is_superuser:
raise Http404
form = PostForm(request.POST or None, request.FILES or None)
if form.is_valid():
instance=form.save(commit=False)
instance.user = request.user
instance.save()
messages.success(request, "Succesfully created")
return HttpResponseRedirect(instance.get_absolute_url())
context = {
"form":form,
}
return render(request, "post_form.html", context)
我非常感谢你的帮助!
在服务器上,此行显示为黄色:"GET /media/media_copy.png HTTP/1.1" 404 94
PS这里是测试post