3

I don't really know how to explain well my issue. What I'm trying to do is the following.

My admins linked my Django server address 192.168.2.1:8001 to a web address: devel.genesilico.pl/modomics to make public the website that otherwise would be visible only on our local network.

If I visit that address I see the main page of my site without the static files, and if I try to visit another page the address changes to:

devel.genesilico.pl/modifications

So the modomics prefix path is removed and it cannot find the page.

I thought that changing my URLs.py adding modomics in front of all of them would resolve this issue, but no. At this point, the DEBUG of Django shows me this (photo attached).And also in this case the prefix "modomics" is removed.

I don't know what to do. I don't know if this problem is given by Django or by the setup of the web address that my admins gave me.

enter image description here

Note that I'm testing this only for the app Modifications.

Here my main urls.py:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('core.urls')),
    url(r'^', include('modifications.urls')),
    url(r'^', include('sequences.urls')),
    url(r'^', include('pathways.urls')),]

And here the urls.py for the app modifications:

urlpatterns = [
    url(r'^modomics/modifications$', views.modlist, name='modlist'),
    url(r'^modomics/modifications/(?P<mod_name>.+)/$', views.moddescription, name='moddescription'),
]
Peter
  • 216
  • 1
  • 14
  • show your urls.py – Usman Maqbool Apr 26 '18 at 08:13
  • Note that you shouldn't use `DEBUG=True` or the Django runserver on a public website. It's insecure. – Alasdair Apr 26 '18 at 09:00
  • Thanks @Alasdair, I know that. In fact, this is a developer version of the webserver. – Peter Apr 26 '18 at 11:53
  • Anyone can access your developer site using the URL in your question. As I said, you shouldn’t do that, it’s insecure. – Alasdair Apr 26 '18 at 11:57
  • @Alasdair you are out of topic. – Peter Apr 26 '18 at 14:06
  • Perhaps, but you might get more answers to your question if you deploy Django properly. Some users don't want to help you to do something which is bad practice and insecure. Even if you are already aware that you are doing something insecure and accept the risks, it's good to warn future readers. – Alasdair Apr 26 '18 at 14:23

1 Answers1

2

It looks like you need to configure your application to run on a sub-folder.

What's happening is that the reverse function is producing relative URLs to a root directory, /, instead of /modomics because your server isn't aware it's being hosted differently.

There are two ways to solve this:

  1. In settings.py, you can set FORCE_SCRIPT_NAME = '/modomics' to get the URLs to generate properly, or

  2. have your admins pass /modomics as the value of a header X-Script-Name and process it in wsgi.py - see this related answer

The drawback to the first solution is that you need to make sure that your website is configured to run differently in development and prod by using one of the settings file patterns for deployment, and you need to coordinate with your admins if the subfolder ever changes.

Community
  • 1
  • 1
whp
  • 1,406
  • 10
  • 10
  • a little more: You'll probably want to adjust your urls.py accordingly (assume `/modomics` is added to the beginning of every single URL). And disable DEBUG in public-facing sites for security – whp Apr 26 '18 at 16:01
  • Thank you very much, this is what I was looking for. I have a similar web server that was deployed in the same manner, but that works. Probably the administrators forgot to do what you wrote as the second answer. – Peter Apr 26 '18 at 16:15