'Flask API throws internal server error on production server, while working perfectly on local machine

I have created a simple website and deployed it to namecheap shared hosting. Every API endpoints work perfectly, except one. One of my API endpoints throws internal server error, while working perfectly on local machine. I have been struggling to solve the issue all day but could not find any solution.

My API is this:

@admin.route('/admin/form_requests/<int:id>', methods=['GET'])
@login_required
def request_details(id):
    request = FormRequests.query.get(id)
    return render_template('admin/request-detail.html', request=request, title='Requests')

class FormRequests(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name_surname = db.Column(db.String(), nullable=False)
    email_address = db.Column(db.String(), nullable=False)
    subject = db.Column(db.String(), nullable=False)
    message = db.Column(db.String(), nullable=False)
    images = db.Column(ARRAY(db.String()))
    date = db.Column(db.DateTime(), default=datetime.utcnow)

First one throwing error, whereas this one below working perfectly:

admin.route('/admin/form_requests', methods=['GET'])
@login_required
def form_requests():
    requests = db.session.query(FormRequests)
    return render_template('admin/requests.html', title='Requests', requests=requests)

Can anyone see the mistake that I made?



Solution 1:[1]

I solved the problem. It was due to my jinja2 template. It was using a custom date formatter:

            <p class="text-dark">{{request.date|format_datetime('full')}}</p>

It works on local environment but somehow does not work on production server. I modified it like this:

            <p class="text-dark">{{request.date.strftime('%d-%m-%Y %H:%M:%S')}}</p>

It works now. Hope this will help someone who gets the same error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kemal PEHL?VAN