0

enter image description here

This is what I got. I applied CSS and JS file, but they don't work.

Error message:

  1. Resource interpreted as Stylesheet but transferred with MIME type text/html: "<URL>"
  2. Uncaught SyntaxError: Unexpected token <

Start.py (actually, I use blueprint)

@app.route('/login', methods=['POST','GET'])   
def login():
    if request.method == 'GET':
        # 쿠키 획득
        uid = request.cookies.get('uid')
        # 최초에 쿠키가 없으면 uid값에 none뜨는걸 방지해줌.
        if not uid:
            uid = ''
        config.cookie_uid = uid
        return render_template('login.html', config=config)

login.html

<!DOCTYPE html>
<html lang="ko">
<head>
{% include ["common/head.html"] %}
</head>
<body>
(omit text)
    {% include "common/foot.html" %}
</body>
</html>

head.html

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <!--모바일화 기능-->
<meta name="description" content="">
<meta name="author" content="">

<title>{{ config.title }}</title>

<!-- Bootstrap Core CSS -->
<link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="/static/vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="/static/dist/css/sb-admin-2.css" rel="stylesheet">

<!-- Morris Charts CSS -->
<link href="/static/vendor/morrisjs/morris.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="/static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

foot.html

<script src="/static/vendor/jquery/jquery.min.js"></script>

<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>

<script src="/static/vendor/metisMenu/metisMenu.min.js"></script>

<script src="/static/dist/js/sb-admin-2.js"></script>

As I think, these are needed files. How can I apply css and js file to flask server?

Seanny123
  • 8,776
  • 13
  • 68
  • 124
유승우
  • 27
  • 3

1 Answers1

0

In the head tag of your html files... use url_for to import your stylesheet maybe? Just a thought... but this is what I use for Flask:

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

Here’s a similar post that may help. Good luck... Link to Flask static files with url_for