python - AssertionError: View function mapping is overwriting an existing endpoint function: EMPTY? -


any suggestion toward clean solution appreciated.

i trying add static files existing app, static folder other files set. define several routes based on list, goal able add files.

the problem receive instead of working program, "endpoint function" isn't detected.

output:

 {'/file1.js': <function func @ 0x10aedfed8>, '/file2.js': <function func @ 0x10aeea050>}  {'/file1.js': <function func @ 0x10aedfed8>, '/file2.js': <function func @ 0x10aeea050>}  traceback (most recent call last):    file "flaskweird.py", line 29, in <module>      app.add_url_rule(d, '', app.serv_deps[d])    file "/library/python/2.7/site-packages/flask/app.py", line 62, in wrapper_func      return f(self, *args, **kwargs)    file "/library/python/2.7/site-packages/flask/app.py", line 984, in add_url_rule 'existing endpoint function: %s' % endpoint)  assertionerror: view function mapping overwriting existing endpoint function: 

code :

from flask import flask app = flask(__name__)  def gen_serv_dep(path):     fp = 'ui' + path  # path starts /     open(fp) f:         content = f.read()     if path.endswith('.css'):         mime = "text/css"     elif path.endswith('.js'):         mime = "text/javascript"     else:         mime = "text"     def func():         #this.__name__ = path  # doesn't change         return response(response=content, status=200, mimetype=mime)     return func  deps = ['/file1.js', '/file2.js'] app.serv_deps = {} d in deps:     app.serv_deps[d] = gen_serv_dep(d) d in deps:     print(app.serv_deps) app.add_url_rule(d, '', app.serv_deps[d])  @app.route('/') def hello_world():     return 'hello, world!' 

sample files serve:

mkdir ui echo "test1" > ui/file1.js echo "test2" > ui/file2.js 

flask==0.10.1

"because passed empty string add_url_rule multiple times in loop. pick unique name each time." -- davidism

this works fine

for d in deps:     app.add_url_rule(d, d, app.serv_deps[d]) 

thanks


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -