Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

Flask example view function error #90

Closed fnokeke closed 7 years ago

fnokeke commented 7 years ago

For some reason, flask_tut has view function error:

AssertionError: View function mapping is overwriting an existing endpoint function: home

This error typically happens when views have the same name but none of the views share the same name. In fact, I noticed that the server won't start with any view added in __init__.py.

I tried changing changing the names of view but the server only runs when all the views are commented out.

Any tips?

Pegase745 commented 7 years ago

Looks like you're right ! Have you tried with a newer virtualenv ? I don't really know much more about Flask but will try to look at it. @tdamsma any idea on this ?

fnokeke commented 7 years ago

Been at it for some time now. Tried new virtualenv but still no luck.

tdamsma commented 7 years ago

Ok, so the issue is that the app is defined in the models.py as app = Flask(__name__). If you move this to the __init__.py this solves the routing issues. Unfortunately, there is now a circula dependency where you need to import the app from the init.py in the models.py, and import the User and Address from the models.py in the init.py. This is as always discussed on SO, but I haven't found a nice example implementation yet. Perhaps it would be sufficient for the example to combine everything in one file?

tdamsma commented 7 years ago

More info on how to structure the example: http://flask.pocoo.org/docs/0.12/patterns/packages/

Pegase745 commented 7 years ago

Nice catch. We'll just have to keep it simple as it is only an example app that's lighter than the pyramid one

Le 23 avr. 2017 8:29 PM, "Thijs Damsma" notifications@github.com a écrit :

More info on how to structure the example: http://flask.pocoo.org/docs/0. 12/patterns/packages/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Pegase745/sqlalchemy-datatables/issues/90#issuecomment-296473942, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmd0R4-XYTB8gBp7VVMiPd6Y7dAL4H5ks5ry5iigaJpZM4NFMkP .

tdamsma commented 7 years ago

I am now fiddling with splitting the app, almost there. Am boarding in 5 mins, will commit it when I land. If it gets too messy, then I'll try an all in one version. Or maybe we should revert to you original working example?

fnokeke commented 7 years ago

Made some progress.

Import directly from models in line 6 of __init__.py from. Precisely, change from flask_tut.models import to from models import and it works.

tdamsma commented 7 years ago

See here for some ideas;:

https://github.com/tdamsma/sqlalchemy-datatables/tree/flask_example_update https://github.com/tdamsma/sqlalchemy-datatables/tree/flask_example_split_code

In one branch I splitted the code over several files, in the other I merged it all in one

saifraider commented 7 years ago

If you would like to see the working structured application of flask using postgres, Jquery, Ajax, CSS, JS, etc. for full stack web development python, take a look at https://github.com/saifraider/FullStackPython