Search code examples
pythonflaskweb-applicationsjinja2

jinja2.exceptions.TemplateSyntaxError: expected token ',', got 'string' and TypeError: 'function' object is not subscriptable


I try to run /homepage

@app.route('/')
def index():   
    return redirect(url_for(homepage))


@app.route('/homepage')
def homepage():
    return render_template('fullcalendar.html')

Got that error:

TypeError: 'function' object is not subscriptable

this error show up when i write in the address bar 127.0.0.1:5000/homepage:

  File "/home/pc/shudleApp1/env/lib/python3.6/site-packages/flask/helpers.py", line 318, in url_for
if endpoint[:1] == ".":

TypeError: 'function' object is not subscriptable

fullcalendar.html

<link href="{{ url_for('static', filename=css/fullcalendar.css') }}"/>
<link href="{{ url_for('static', filename= css/fullcalendar.print.css') }}" />
<script src="{{ url_for('static', filename=js/jquery-1.10.2.js' }}"></script>
<script src="{{ url_for('static', filename=js/jquery-ui.custom.min.js') }}"></script>
<script src="{{ url_for('static', filename=js/fullcalendar.js') }}"></script>
<script>

Solution

  • in redirect(url_for(homepage)) you are passing to url_for the homepage which is your function and not your homepage endpoint.

    You should pass '/homepage'