1

After deploy my django site on heroku all pages works fine except one page which is (view page) and that shows server error(500) on it.

Code in settings:

DEBUG = False

ALLOWED_HOSTS = ['.herokuapp.com', '127.0.0.1']

Code in View page:

# 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)

If anyone knows this error. Kindly let me know

MathCrackExchange
  • 595
  • 1
  • 6
  • 25
Asif Ayub
  • 25
  • 6
  • Can you also share the view function which renders the page and is giving error? – Pratik149 May 20 '20 at 21:40
  • Above I mention views page, here customer_data shows this error. – Asif Ayub May 20 '20 at 22:21
  • Please see this answer https://stackoverflow.com/questions/61854083/django-heroku-server-error-500-when-i-set-debug-false-on-true-it-is-working/61854448#61854448 – Hisham___Pak May 21 '20 at 02:09
  • From these three which page gives you 500 error? Dashboard.html, Products.html or customer_data.html ? – Pratik149 May 21 '20 at 06:06
  • Thanks Hisham__Pak and Pratik149 . Actually issue was with customer_data in views page where I render it. After removing that error, it works fine. – Asif Ayub May 22 '20 at 20:45

1 Answers1

0

If anyone is also having this problem and no other solution seems to be fixing it, then try this.

Run locally with DEBUG=False, and you might see a "StopIteration" on a URL in one of your templates. Check and make sure you use forward slashes there, and not backslashes. This was causing the Server 500 error both locally & remotely with DEBUG=False, while it works locally and remotely with DEBUG=True.

See this post on the Django forums for more info on that: Django forum post.

I would normally use forward slashes, however a BootstrapStudio to Django template export script is generating backslashes. I just have to patch the export script code (a Python script).

MathCrackExchange
  • 595
  • 1
  • 6
  • 25