500 Server Error | Impossible to Fix

2,311 views
Skip to first unread message

Lightning Bit

unread,
Aug 28, 2020, 7:06:04 PM8/28/20
to Django users
Greetings all, 

I finally finished developing a Django website. 

In the terminal I checked: 

> python manage.py check --deploy

There were no errors and the program was ready for deployment. I even ran a:

> python manage.py runserver

There were also no errors on this end. Upon successfully porting the website to Heroku, I unfortunately got a 500 Server Error and then after editing, a 400 Server Error. I resolved the 400 Server Error by returning to the terminal and doing the following:

>python manage.py collectstatic

This resolved the 400 Server Error after pushing the data to the Heroku Master. Sadly, the 500 Server Error remained. I did a bit more research and discovered that 500 Server Errors usually arise from a syntax error in an HTML file or external file. I sifted for hours and did not find a syntax error. 

Could there be an alternative fix to the 500 Server Error that appears on the website? Does anyone know how to fix this? At this point, I feel as though I spent months developing this website for nothing. 

Please help if possible. Thank you! 

- Lightning Bit

RANGA BHARATH JINKA

unread,
Aug 28, 2020, 9:59:43 PM8/28/20
to django...@googlegroups.com
Hi,

    In settings turn the debug to True. Then check the error in terminal.

In heroku you have to check the logs in the terminal using heroku logs --tail

All the best 👍

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cbe73ae9-c7c7-41de-95d5-1fab09ffdc17n%40googlegroups.com.

King Niko

unread,
Aug 29, 2020, 10:55:54 AM8/29/20
to django...@googlegroups.com
Thank you so much for the help. The:

> heroku logs --tail

Definitely shows all of the errors. Two common errors that I have witnessed is:

> "GET / HTTP/1.1" 500 145 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"

>"GET /favicon.ico HTTP/1.1" 404 179 "https://samplesite.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"

These are both external errors. The first is a 500 error from Heroku and the second is a 400 error from Favicon. Any idea on how to resolve this issue?

Thank you again!

King Niko

unread,
Aug 29, 2020, 11:25:51 AM8/29/20
to django...@googlegroups.com
I managed to resolve the favicon 400 error. However, there still resides the Heroku error:

> at=info method=GET path="/" host=samplesite.herokuapp.com request_id= "private" fwd="private" dyno=web.1 connect=1ms service=99ms status=500 bytes=477 protocol=https

Any suggestions? Thank you!

Kunal Solanke

unread,
Aug 29, 2020, 11:42:10 AM8/29/20
to django...@googlegroups.com
500 is actually a internal server error ,it can easily resolved by just looking at the logger ,it dosen't only mean syntax error and definately not syntax errors of html file .Html file syntax errors are simply ignored I think you meant jinja code.Basic way to go around these is simply check the logger of your server ,see it will mention file and line where your code breaks and if its mentionaling terms like template loader and etc then your jinja code is wrong .



These error mostly occur at deploy or at time of fetching .


1.Deploy 
  Mostly problem with config vars

2.Fetching 
  Code is breaking somewhere.

King Niko

unread,
Aug 29, 2020, 11:49:56 AM8/29/20
to django...@googlegroups.com
Thank you for the feedback!

Intriguing, above the 500 error I see the following line: 

> Cart: {} 

In fact, I have a line in one of my HTML files that says Cart: {} under the JavaScript sector. Maybe this is the bug that needs to be fixed? 

The cart error plus the Heroku error are quite troublesome. I believe that the Heroku error may be able to be resolved via adding the full web address to ALLOWED_HOSTS in "settings.py". Time for a few test runs.

King Niko

unread,
Aug 29, 2020, 2:32:54 PM8/29/20
to django...@googlegroups.com
Last Two 500 Errors:

> "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/ - (KHTML, like Gecko) Chrome/ - Safari/ -"

> at=info method=GET path="/" host=samplesite.herokuapp.com request_id=private fwd="private" dyno=web.1 connect=1ms service=116ms status=500 bytes=477 protocol=https

Both of these errors are very vague and provide no direction for resolution. Has anyone ever encountered this before? 

Thanks!

Kasper Laudrup

unread,
Aug 29, 2020, 3:19:13 PM8/29/20
to django...@googlegroups.com
Hi King Niko,

On 29/08/2020 20.31, King Niko wrote:
>
> Both of these errors are very vague and provide no direction for
> resolution. Has anyone ever encountered this before?
>

I don't know anything about deploying on Heroku, but as others have
pointed out, you should definitely look into how to get some more
detailed log information:

https://docs.djangoproject.com/en/3.1/topics/logging/

I've personal set up my logging so I get an email with detailed
information in case of an internal server error. That works quite well
for my use case, but yours might be very different.

There's no reason wasting time trying to guess what is wrong, you want
to be able to get hold of the detailed error information sooner or later
anyway so start by figuring out how you can do that as the very first thing.

Kind regards,

Kasper Laudrup

King Niko

unread,
Aug 30, 2020, 7:53:54 AM8/30/20
to django...@googlegroups.com
Thanks for the suggestion Kasper.
Unfortunately I have not been able to resolve the above bugs utilizing the recommended logging technique. The:

> heroku logs —tail 

Works to give me the errors mentioned previously. I just wish that there was a way for heroku itself to provide more detailed and precise 500 server errors. The current logs for Heroku is not informative enough. 

--

You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

RANGA BHARATH JINKA

unread,
Aug 30, 2020, 8:33:14 AM8/30/20
to django...@googlegroups.com
Hi,

   Copy and paste your log errors . I will check once



--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

King Niko

unread,
Aug 30, 2020, 9:07:15 AM8/30/20
to django...@googlegroups.com
Hi Ranga, 

These are the last two log errors:


> "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/ - (KHTML, like Gecko) Chrome/ - Safari/ -"

> at=info method=GET path="/" host=samplesite.herokuapp.com request_id=private fwd="private" dyno=web.1 connect=1ms service=116ms status=500 bytes=477 protocol=https

Thanks Ranga!

RANGA BHARATH JINKA

unread,
Aug 30, 2020, 9:17:52 AM8/30/20
to django...@googlegroups.com
Hi, 

    Please check the whole log errors line by line. Then only u can find the exact error

King Niko

unread,
Aug 30, 2020, 2:30:09 PM8/30/20
to django...@googlegroups.com
Okay, so I added a logging to:

> python manage.py runserver

And I found the error (which also now appears in "heroku logs --tail"). Interestingly, this thing states that:

> django.template.exceptions.TemplateDoesNotExist: store/main.html

This is impossible because in  urls.py I have my main as my base url: 

> urlpatterns = [
     path('  ' , views.main, name="main")
]

Also, in views.py I have main instantiated as:

def main(request):
    
    data= cartData(request)

    items=data['items']
    order=data['order']
    cartItems=data['cartItems']

    context = {'items':items, 'order':order, 'cartItems':cartItems}
    return render(request, 'store/main.html', context)

 
Thus I am confused as to how the Template could be non-existent if it does in fact exist. Would you all happen to know of any solutions to this?


RANGA BHARATH JINKA

unread,
Aug 31, 2020, 1:07:39 AM8/31/20
to django...@googlegroups.com
Hi, 

    You have to add templates location in settings.py as  'DIRS': [os.path.join(BASE_DIR, 'templates')].

     Create a templates folder where manage.py file exists i.e. your project root directory and move all your templates there like html files.

     All the best.


Reply all
Reply to author
Forward
0 new messages