页面未找到(404)页面未找到(404)页面未找到
(因为我已经打开了调试的确切错误)。
我得到这个错误,当我试图打开我的形象在新的标签,它是不显示后,部署在铁路,我已经上传了图像后,部署在https://web-production-08528.up.railway.app/admin/它是工作正常,当我使用localhost
settings.py
DEBUG =True
#DEBUG = config('DJANGO_DEBUG', '') != 'False'
ALLOWED_HOSTS = ['web','127.0.0.1:8000']
# Application definition
INSTALLED_APPS = [
'shop',
'cart',
'orders',
'payment',
'phone_field',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'myshop.urls'
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS=[
BASE_DIR.joinpath('static')
]
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'media'
CART_SESSION_ID='cart'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
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
admin.site.site_header = 'Admin Panel'
urlpatterns = [
path('admin/', admin.site.urls),
path('cart/',include('cart.urls',namespace="cart")),
path('orders/',include('orders.urls',namespace='orders')),
path('payment/',include('payment.urls',namespace='payment')),
path('',include('shop.urls',namespace="shop")),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
模板
<img src="{{product.image.url}}" alt="" height="500px" width="300px">
<form action="{% url 'cart:cart_add' product.id %}" method='post'>
{{cart_add_product_form}}
<input type="submit" value='Add to Cart' id="submit">
{% csrf_token %}
</form>
</div>
1条答案
按热度按时间0h4hbjxa1#
我想你在
urls.py
中漏掉了一些代码。您必须在开发过程中包括提供媒体文件所需的配置: