Base URL #2

Closed
opened 2018-11-28 21:35:47 +01:00 by kmlucy · 12 comments

Is there a way to run this with a base URL, for example, at https://URL/hrss/?

Is there a way to run this with a base URL, for example, at `https://URL/hrss/`?
Owner

Hello @kmlucy,

with the latest commit I have just pushed, you can edit hrss/urls.py and prepend the urls with a custom prefix such as hrss.

For example,

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'', include('web.urls')),
]

will become

urlpatterns = [
    path('hrss/admin/', admin.site.urls),
    url(r'hrss/', include('web.urls')),
]

Please confirm that it worked (or not!).

Hello @kmlucy, with the latest commit I have just pushed, you can edit `hrss/urls.py` and prepend the urls with a custom prefix such as `hrss`. For example, ```python urlpatterns = [ path('admin/', admin.site.urls), url(r'', include('web.urls')), ] ``` will become ```python urlpatterns = [ path('hrss/admin/', admin.site.urls), url(r'hrss/', include('web.urls')), ] ``` Please confirm that it worked (or not!).
Author

Thanks for the quick update. It kinda works, but with a few issues. I also had to change /static/ to /hrss/static/ in hrss/settings.py.

In addition, the HRSS link in the top left redirects to the root of the domain, as does the New link in the top right.

And when I try to add a feed, it throws a MethodNotAllowedHttpException error. I think there is something else that is trying to redirect to the root. Do I also need to update web/urls.py?

Thanks for the quick update. It kinda works, but with a few issues. I also had to change `/static/` to `/hrss/static/` in `hrss/settings.py`. In addition, the `HRSS` link in the top left redirects to the root of the domain, as does the `New` link in the top right. And when I try to add a feed, it throws a `MethodNotAllowedHttpException` error. I think there is something else that is trying to redirect to the root. Do I also need to update `web/urls.py`?
Owner

The HRSS link redirection on the top left has been fixed in my last commit f61a6c42c5. Are you sure you updated your instance to this commit?

No need to update web/urls.py. If you have other errors, can you please send me the logfile?

The `HRSS` link redirection on the top left has been fixed in my last commit f61a6c42c554a3c387d9c65ce56beedb3ca4195e. Are you sure you updated your instance to this commit? No need to update `web/urls.py`. If you have other errors, can you please send me the logfile?
Author

That was my bad, I didn't have the latest commit. I do still have to change the static path, but the other problems went away.

I also had to revert the changes to context_processor.py, otherwise I got this error:

IndexError at /hrss/
list index out of range
Request Method:	GET
Request URL:	http://FQDN/hrss/
Django Version:	2.1.3
Exception Type:	IndexError
Exception Value:	
list index out of range
Exception Location:	/hrss/web/context_processor.py in BASE_URL, line 10
Python Executable:	/usr/local/bin/python3
Python Version:	3.7.1
Python Path:	
['/hrss',
 '/usr/local/lib/python37.zip',
 '/usr/local/lib/python3.7',
 '/usr/local/lib/python3.7/lib-dynload',
 '/usr/local/lib/python3.7/site-packages']
Server time:	Thu, 29 Nov 2018 12:35:56 +0000
That was my bad, I didn't have the latest commit. I do still have to change the static path, but the other problems went away. I also had to revert the changes to `context_processor.py`, otherwise I got this error: ``` IndexError at /hrss/ list index out of range Request Method: GET Request URL: http://FQDN/hrss/ Django Version: 2.1.3 Exception Type: IndexError Exception Value: list index out of range Exception Location: /hrss/web/context_processor.py in BASE_URL, line 10 Python Executable: /usr/local/bin/python3 Python Version: 3.7.1 Python Path: ['/hrss', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages'] Server time: Thu, 29 Nov 2018 12:35:56 +0000 ```
Owner

I have modified the way BASE_URL could be implemented. Please pull latest commit (af9b1f0c5d) and be sure to change the BASE_URL setting in hrss/setting.py.

Every other modification you made should be cleared to make it work (hopefully). context_processor now use a completely different way to determine the variable. Be sure to reset this file as well.

Please let me know if this worked (tested in dev+demo website and seems to be working, so...).

I have modified the way BASE_URL could be implemented. Please pull latest commit (af9b1f0c5d9b9069b46670b465921eda11f28eca) and be sure to change the BASE_URL setting in hrss/setting.py. Every other modification you made should be cleared to make it work (hopefully). `context_processor` now use a completely different way to determine the variable. Be sure to reset this file as well. Please let me know if this worked (tested in dev+demo website and seems to be working, so...).
Author

I like this solution a lot more. I was able to remove every modification bar one. The STATIC_URL variable in settings.py still needs to be updated since it is hardcoded. So to make it work, I have to set BASE_URL = "https://FQDN/hrss" and STATIC_URL = '/hrss/static/'.

Is there a way to make the static url relative?

I like this solution a lot more. I was able to remove every modification bar one. The `STATIC_URL` variable in `settings.py` still needs to be updated since it is hardcoded. So to make it work, I have to set `BASE_URL = "https://FQDN/hrss"` and `STATIC_URL = '/hrss/static/'`. Is there a way to make the static url relative?
Owner

I have never edited STATIC_URL for any of my servers. Local uses python integrated webserver and works fine, and demo is behind nginx+uwsgi and works also fine out of the box. Are you perhaps using Apache?

I use python3 manage.py collectstatic after my pull.

I have never edited `STATIC_URL` for any of my servers. Local uses python integrated webserver and works fine, and demo is behind nginx+uwsgi and works also fine out of the box. Are you perhaps using Apache? I use `python3 manage.py collectstatic` after my pull.
Author

I'm using nginx. If I don't edit STATIC_URL, none of the css or images load. Are you running in a subdirectory?

I'm using nginx. If I don't edit `STATIC_URL`, none of the css or images load. Are you running in a subdirectory?
Owner

I don't, but for the sake of this issue I added a subdirectory and it worked without editing STATIC_URL. If I add a subdirectory to STATIC_URL, the assets stop loading on my end.

Does it work when using the debug webserver python manage.py runserver?

I don't, but for the sake of this issue I added a subdirectory and it worked without editing `STATIC_URL`. If I add a subdirectory to `STATIC_URL`, the assets stop loading on my end. Does it work when using the debug webserver `python manage.py runserver`?
Author

This is using the debug server. It's not super important, it's easy enough to change both places.

This is using the debug server. It's not super important, it's easy enough to change both places.
Owner

Autoclosed the issue by mistake. 2876fe663d should fix your issue. Can you confirm that you only have to change the BASE_URL now?

Autoclosed the issue by mistake. https://hipstercat.fr/gogs/hipstercat/hrss/commit/2876fe663d406a7b0a3170dd366aef3dc2622a1f should fix your issue. Can you confirm that you only have to change the `BASE_URL` now?
Author

That did the trick, only BASE_URL needs to be changed. Thanks for the fix!

That did the trick, only `BASE_URL` needs to be changed. Thanks for the fix!
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hipstercat/hrss#2
No description provided.