Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know how you could do with all the views routed by the same module.</p> <p>What I usually do is separate my views in different modules (like you did with module <code>A</code> and <code>B</code>), and register them as blueprints, after that, when using the <code>url_for()</code> function, you can prefix the view name with your blueprint name and then avoid conflicts and potential problems.</p> <p>Here is an example:</p> <p><strong>main_views.py:</strong></p> <pre><code>from flask import Blueprint main = Blueprint('main', __name__) @main.route('/') def index(): pass </code></pre> <p><strong>admin_views.py:</strong></p> <pre><code>from flask import Blueprint admin = Blueprint('admin', __name__) @admin.route('/admin') def index(): pass </code></pre> <p><strong>application.py:</strong></p> <pre><code>from flask import Flask from main_views import main from admin_views import admin app = Flask('my_application') app.register_blueprint(main) app.register_blueprint(admin) </code></pre> <p>Now, to access the 2 index views and still distinguish one from the other, just use <code>url_for('main.index')</code> or <code>url_for('admin.index')</code></p> <h2>EDIT:</h2> <p>Just one more useful details about routing using blueprints, when registering the blueprint, you can pass a <code>url_prefix</code> argument, that will apply to every view within this blueprint.</p> <p>For example, given the following code:</p> <p><strong>admin_views.py</strong></p> <pre><code>from flask import Blueprint admin = Blueprint('admin', __name__) @admin.route('/') def index(): pass @admin.route('/logout') def logout(): pass </code></pre> <p><strong>application.py:</strong></p> <pre><code>from flask import Flask from admin_views import admin app = Flask('my_application') app.register_blueprint(admin, url_prefix='/admin') </code></pre> <p>The 2 views would be available at the URL <code>/admin/</code> and <code>/admin/logout</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload