0

My App structure is like below :

--app
  --app.py
  --static
    --js
      --app.js
    --css
    --partial
      --home.html
  --templates
    --index.html

Already gone through this , but it is different

my app.py

@app.route("/")
def index():
    return send_file('static/partial/home.html')
    #tried with below as well
    #return make_response(open('static/partial/index.html').read())

my app.js

use strict';
var guts = angular.module('app', ['ngSanitize', 'ngCookies']);

my index.html

<!DOCTYPE html>
   <html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="app" ng-controller="appcontroller">
     <head>
     </head>

The error coming while hosting app on local server is :

IOError: [Errno 2] No such file or directory: 'C:\\..\\..\\..\\..\\..\\app\\templates/index.html' , i tried changing this backslash with other options , not luck

P.S I dont want to use jinja templates Also i am referencing this blog as reference. Any leads on this ?

[Updated] : final goal is to render home.html which is there @static/partial

1 Answer 1

1

That should be return render_template('index.html'). Regardless of whether or not it actually has jinja template code, Flask won't be able to find it unless you specify it's a template file (or use send_from_directory directly).

If you really want to use send_file like in the blog post you linked, make the view function return send_file(os.path.join('templates', 'index.html')) which will take care of all the slash nonsense for you.

Sign up to request clarification or add additional context in comments.

4 Comments

have you seen the reference link i have pasted in question , it seems they are rendering it also what if i dont wanna use Jinja templates , can't i achieve it ?
render_template is just being used for convenience; your index.html doesn't actually have any jinja code and thus will be sent as-is. The send_file method is much more brittle as it uses relative paths that could be invalid depending on how the app is run or installed.
thanks for the direction , I have update the question : can you put some points on that
Ah, then just change the send_file join to 'static', 'partial', 'index.html'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.