В Flask мы можем добиться этого следующим образом:
Код: Выделить всё
@app.errorhandler(404)
def handle_404(e):
if request.path.startswith('/api'):
return render_template('my_api_404.html'), 404
else:
return redirect(url_for('index'))
Код: Выделить всё
from django.shortcuts import redirect
def view_404(request, exception=None):
return redirect('/')
Подробнее здесь: https://stackoverflow.com/questions/629 ... ecting-404