E
E
eifory2019-06-16 17:15:47
css
eifory, 2019-06-16 17:15:47

Adding a Variable Part to the URL Causes a CSS Backlog?

there is such a route, the page is successfully rendered with CSS

@app.route('/test/<version>')
def func1(version):
    return render_template('index.html', version=version)

when adding a variable part to the url, the same page is rendered but without css
@app.route('/test/<version>/<num>')
def func1(version, num):
    return render_template('index.html',version=version, num=num)

here is a piece of index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../static/style.css">
</head>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-06-16
@eifory

Because your stylesheet URL is relative. Get absolute as described in the documentation :

<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question