Flask + Jinja2 Script imports
up vote
0
down vote
favorite
I'm having an issue when using Flask and it's templates when importing Scripts and Stylesheets. I searched everywhere how to do it, and none of them solved my problem.
This is my project's structure:
https://i.gyazo.com/f746c58499cbbafa11b023eecb316b15.png
This is how I defined Flask's configuration:
app = Flask(__name__,
template_folder="../web/templates",
static_folder="../web/static",
static_url_path=''
)
And this is how i'm importing the scripts :
<script src= url_for('static', filename='/js/home.js') ></script>
And this is the msg I get :
Falló la carga de con fuente “http://localhost:5000/js/home.js”.
(Basically says that it failed loading that script)
I already read the Quickstart guide from Flask.
I tried creating a "static" folder in the project's root and not setting anything on the config. Tried to change the static folder everywhere on my project.
Can anyone help me solve this? I'm new to Flask and Jinja, but have been searching the whole day and can't make it work.
NOTE : The path for the templates work, my templates work fine, except for .js and .css imports.
javascript python flask server jinja2
|
show 5 more comments
up vote
0
down vote
favorite
I'm having an issue when using Flask and it's templates when importing Scripts and Stylesheets. I searched everywhere how to do it, and none of them solved my problem.
This is my project's structure:
https://i.gyazo.com/f746c58499cbbafa11b023eecb316b15.png
This is how I defined Flask's configuration:
app = Flask(__name__,
template_folder="../web/templates",
static_folder="../web/static",
static_url_path=''
)
And this is how i'm importing the scripts :
<script src= url_for('static', filename='/js/home.js') ></script>
And this is the msg I get :
Falló la carga de con fuente “http://localhost:5000/js/home.js”.
(Basically says that it failed loading that script)
I already read the Quickstart guide from Flask.
I tried creating a "static" folder in the project's root and not setting anything on the config. Tried to change the static folder everywhere on my project.
Can anyone help me solve this? I'm new to Flask and Jinja, but have been searching the whole day and can't make it work.
NOTE : The path for the templates work, my templates work fine, except for .js and .css imports.
javascript python flask server jinja2
1
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
In which folder does your.py
file lives and where do you run it from?
– Edgar R. Mondragón
Nov 10 at 2:43
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
I have to ask... what do the file structure insideweb/static/js
look like.
– Edgar R. Mondragón
Nov 10 at 2:57
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm having an issue when using Flask and it's templates when importing Scripts and Stylesheets. I searched everywhere how to do it, and none of them solved my problem.
This is my project's structure:
https://i.gyazo.com/f746c58499cbbafa11b023eecb316b15.png
This is how I defined Flask's configuration:
app = Flask(__name__,
template_folder="../web/templates",
static_folder="../web/static",
static_url_path=''
)
And this is how i'm importing the scripts :
<script src= url_for('static', filename='/js/home.js') ></script>
And this is the msg I get :
Falló la carga de con fuente “http://localhost:5000/js/home.js”.
(Basically says that it failed loading that script)
I already read the Quickstart guide from Flask.
I tried creating a "static" folder in the project's root and not setting anything on the config. Tried to change the static folder everywhere on my project.
Can anyone help me solve this? I'm new to Flask and Jinja, but have been searching the whole day and can't make it work.
NOTE : The path for the templates work, my templates work fine, except for .js and .css imports.
javascript python flask server jinja2
I'm having an issue when using Flask and it's templates when importing Scripts and Stylesheets. I searched everywhere how to do it, and none of them solved my problem.
This is my project's structure:
https://i.gyazo.com/f746c58499cbbafa11b023eecb316b15.png
This is how I defined Flask's configuration:
app = Flask(__name__,
template_folder="../web/templates",
static_folder="../web/static",
static_url_path=''
)
And this is how i'm importing the scripts :
<script src= url_for('static', filename='/js/home.js') ></script>
And this is the msg I get :
Falló la carga de con fuente “http://localhost:5000/js/home.js”.
(Basically says that it failed loading that script)
I already read the Quickstart guide from Flask.
I tried creating a "static" folder in the project's root and not setting anything on the config. Tried to change the static folder everywhere on my project.
Can anyone help me solve this? I'm new to Flask and Jinja, but have been searching the whole day and can't make it work.
NOTE : The path for the templates work, my templates work fine, except for .js and .css imports.
javascript python flask server jinja2
javascript python flask server jinja2
edited Nov 10 at 3:29
Edgar R. Mondragón
1,1991618
1,1991618
asked Nov 10 at 2:19
Martin Rios
11
11
1
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
In which folder does your.py
file lives and where do you run it from?
– Edgar R. Mondragón
Nov 10 at 2:43
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
I have to ask... what do the file structure insideweb/static/js
look like.
– Edgar R. Mondragón
Nov 10 at 2:57
|
show 5 more comments
1
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
In which folder does your.py
file lives and where do you run it from?
– Edgar R. Mondragón
Nov 10 at 2:43
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
I have to ask... what do the file structure insideweb/static/js
look like.
– Edgar R. Mondragón
Nov 10 at 2:57
1
1
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
In which folder does your
.py
file lives and where do you run it from?– Edgar R. Mondragón
Nov 10 at 2:43
In which folder does your
.py
file lives and where do you run it from?– Edgar R. Mondragón
Nov 10 at 2:43
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
I have to ask... what do the file structure inside
web/static/js
look like.– Edgar R. Mondragón
Nov 10 at 2:57
I have to ask... what do the file structure inside
web/static/js
look like.– Edgar R. Mondragón
Nov 10 at 2:57
|
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235482%2fflask-jinja2-script-imports%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please consider posting your code bits instead of screenshots.
– Edgar R. Mondragón
Nov 10 at 2:23
Thank you for your input. I'm new to posting in SO.
– Martin Rios
Nov 10 at 2:36
In which folder does your
.py
file lives and where do you run it from?– Edgar R. Mondragón
Nov 10 at 2:43
i.gyazo.com/f44dda71de5b4c746cf7728433fdf445.png This is the project structure. It's being ran from the init inside "controladores", and i'm executing it via IDE (pyCharm)
– Martin Rios
Nov 10 at 2:50
I have to ask... what do the file structure inside
web/static/js
look like.– Edgar R. Mondragón
Nov 10 at 2:57