url_prefix is repeated in the url

38 views
Skip to first unread message

Davidiam

unread,
Sep 9, 2025, 5:33:43 AMSep 9
to py4web
Py4web: 1.20250607.2 on Python 3.13.5
nginx reverse proxy configuration

The url_prefix is repeated in the url in the following scenario:
  • I open the _dashboard app
  • I click on the _scaffold app
  • I go to the Databases in _scaffold
  • I click on auth_user
  • I click on the New button
  • It doubles my url_prefix in the url and gives a 404
Work-around: add a rewrite in my nginx config file to remove one of the 2 prefixes (the url is still incorrect in the hover)

Looking for solution in py4web:
I suspect that it has something to do with an absolute path somewhere instead of a relative path.  Maybe it is in dbabmin.js but I can't access this in my browser debugger for some reason.  

This is what I see when I hover over the New button (server and referrer modified) :

https://server.example.com:XXXX/myurlprefix/myurlprefix/_dashboard/dbadmin/_scaffold/db/auth_user?mode=new&referrer=68747499999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

Any ideas as to where or how to debug this appreciated.

Davidiam

unread,
Sep 26, 2025, 11:28:03 AM (3 days ago) Sep 26
to py4web
Ok, I am beginning to see what is occuring.  The problem seems to come from the grid object when using a reverse proxy:

For some reason the grid object is causing duplicate url_prefixes : Any idea how to fix this? 

In _dashboard layout.html

  <!-- beginning of HTML inserted by extending templatey -->

    <center>

      <div>

        <!-- Flash alert messages, first optional one in data-alert -->

        <flash-alerts class="padded" data-alert="[[=globals().get('flash','')]]"></flash-alerts>

      </div>

      <main class="padded">

        <!-- contect injected by extending page layout.html in dashboard -->

        [[include]]

      </main>

    </center>

    <!-- end of HTML inserted by extending template -->

 

dbadmin.html:

[[extend "layout.html"]]

<h2>Table "[[=table_name]]"</h2>

[[=grid]]  ===========================> This seems to be triggering the double prefixes

 

<a class="grid-new-button info" href="/myfirsteuda/p/myfirsteuda/p/_dashboard/dbadmin/_scaffold/db/auth_user?mode=new&amp;referrer=687474703A2F2F733273303065676B2E62652E7372762E6465762E7379733A383434332F6D796669727374657564612F702F5F64617368626F6172642F646261646D696E2F5F73636166666F6C642F64622F617574685F75736572" role="button"><i class="fas fa-plus"></i><span class="grid-new-button-text">&nbsp;New</span></a>


Message has been deleted

Davidiam

unread,
2:04 AM (3 hours ago) 2:04 AM
to py4web
BUG Found:

The problem occurs in URL line 901 - 906:
In this case, the url_prefix = /myfirsteuda/p
and prefix/myfirsteuda/p/_dashboard/dbadmin/

So once the url is created, it has a double prefix!! : /myfirsteuda/p/myfirsteuda/p/_dashboard/dbadmin/

url_prefix = os.environ.get("PY4WEB_URL_PREFIX", "")
    url = (
        url_prefix
        + prefix
        + "/".join(urllib.parse.quote(part, safe=r":/{}") for part in broken_parts)
    )

I should expect that it would only add the url_prefix if
    • url_prefix is not empty 
    • and prefix is not empty 
    • and prefix does not start with url_prefix

I suspect that someone who knows the code better than I do would find a cleaner fix.

Davidiam

unread,
2:31 AM (3 hours ago) 2:31 AM
to py4web
The code for the url above is in core.py

Davidiam

unread,
4:55 AM (1 hour ago) 4:55 AM
to py4web
The fix that I am using in core.py:
    url_prefix = os.environ.get("PY4WEB_URL_PREFIX", "")
# Fix double url_prefix
    if url_prefix and prefix and prefix.startswith(url_prefix):
        url_prefix = ""

    url = (
        url_prefix
        + prefix
        + "/".join(urllib.parse.quote(part, safe=r":/{}") for part in broken_parts)
    )
On Friday, September 26, 2025 at 5:28:03 PM UTC+2 Davidiam wrote:
Reply all
Reply to author
Forward
0 new messages