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.










share|improve this question



















  • 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














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.










share|improve this question



















  • 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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 inside web/static/js look like.
    – Edgar R. Mondragón
    Nov 10 at 2:57












  • 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







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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo