【发布时间】:2020-05-20 21:20:28
【问题描述】:
在 heroku 上部署我的 django 站点后,所有页面都可以正常工作,除了一个页面是(查看页面)并且在上面显示服务器错误(500)。
设置中的代码:
DEBUG = False
ALLOWED_HOSTS = ['.herokuapp.com', '127.0.0.1']
查看页面中的代码:
# Create your views here.
@login_required(login_url='login')
@admin_only
def dashboard(request):
all_orders=Order.objects.all()
all_customers=customer.objects.all()
order_pending=Order.objects.filter(status='PENDING')
order_out = Order.objects.filter(status='OUT-FOR-DELIEVERY')
order_delievered = Order.objects.filter(status='DELIEVERED')
total_orders=all_orders.count()
total_orders_pending=order_pending.count()
total_orders_out=order_out.count()
total_orders_delievered=order_delievered.count()
context={'orders':all_orders, 'customers':all_customers, 'total_orders':total_orders,
'total_orders_pending':total_orders_pending, 'total_orders_out':total_orders_out,
'total_orders_delievered':total_orders_delievered}
return render(request, 'cms_app/Dashboard.html', context)
@login_required(login_url='login')
@allowed_user(allowed_roles=['admin'])
def product(request):
all_products=Product.objects.all()
context={'all_products':all_products}
return render(request, 'cms_app/Products.html',context)
@login_required(login_url='login')
@allowed_user(allowed_roles=['admin'])
def customer_data(request, id):
customers=customer.objects.get(id=id)
orders=customers.order_set.all()
all_orders=orders.count()
my_filters=OrderFilter(request.GET, queryset=orders)
orders=my_filters.qs
context={'customer_data':customers, 'all_orders':all_orders, 'orders':orders, 'my_filters':my_filters}
return render(request, 'cms_app/customer_Data.html',context)
如果有人知道这个错误。请告诉我
【问题讨论】:
-
能否分享一下渲染页面报错的视图函数?
-
上面我提到了views页面,这里customer_data显示了这个错误。
-
从这三个中哪个页面给你500错误? Dashboard.html、Products.html 或 customer_data.html ?
-
感谢 Hisham__Pak 和 Pratik149。实际上问题出在我呈现它的视图页面中的 customer_data 上。删除该错误后,它工作正常。
标签: django