Wednesday, August 30, 2017

Re: Bizarre URL behaviour after deploying

Mohammad,

> you have to use app_name in url.py in each app

I think you have misunderstood or misread my issue below. Clearly I do not have to use app_name in url.py, because I don't and it works fine. The problem is the complete inverse, namely I have not asked for the app_name to appear in the URL, and it does not appear in the URL with the development server (manage.py runserver)  and suddenly when deployed under lighttpd and uwsgi Django inserts the app_name into the URL without my ever having asked it to!

I want that to go away, I don't want an app_name in my URLs as I have a single app project so to speak.

Here are two people wanting to do the same (remove that from URL):

https://stackoverflow.com/questions/40322042/remove-django-app-name-from-path-with-custom-domain-heroku
https://stackoverflow.com/questions/18764967/django-admin-removing-app-name-from-url-for-single-app-projects

except none of the answers apply to my situation, because I have not ever defined app_name and it has never appeared in URLS so far (when running under  development). They only appeared, out of the blue, when deploying.

The whole project is here:
https://github.com/bernd-wechner/CoGs
and I want to lose app name form my URLs (and ideally understand why they are there to begin with) not add them!

Kind regards,

Bernd

mohammad k wrote:
you have Different app in your project yes ?
you have to use app_name in url.py in each app

like that : 
app_name = 'polls' in polls folder and in url.py

from django.conf.urls import url
from . import views

app_name = 'polls'
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^(?P<pk>[0-9]+)/results/$', views.ResultView.as_view(), name='results'),
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]

you have to create a url.py for each app in them folder

and in url.py beside settings.py use code like that :url('^polls/',include('polls.urls')),

On Wed, Aug 30, 2017 at 4:11 PM, Bernd Wechner <bernd.wechner@gmail.com> wrote:

This has bamboozled me some. And the best thing I've found on-line doesn't seem to apply:

    https://stackoverflow.com/questions/26944908/django-url-mapping-how-to-remove-app-name-from-url-paths

Let me summarise.

I have a site that I've been building and testing with djangos development server of course. And it implements URLS like:

http://127.0.0.1:8000/list/Model
http://127.0.0.1:8000/add/Model
http://127.0.0.1:8000/edit/Model/nn
http://127.0.0.1:8000/view/Model/nn
http://127.0.0.1:8000/delete/Model/nn

Works like a dream, so I'm deploying, locally first, under lighttpd and uwsgi. That is working fine too. Sort of,

These are all reached with links in my templates like yo:

{% url 'list' model %}
{% url 'add' model %}
{% url 'edit' model pk %}
{% url 'view' model pk %}
{% url 'delete' model pk %}

because in urls.py they all have "name"s defined like that.

All honky dory.

Now after deploying everything works nicely, but those same links point to:

http://mysite.tld/app/list/Model
http://mysite.tld/app/add/Model
http://mysite.tld/app/edit/Model/nn
http://mysite.tld/app/view/Model/nn
http://mysite.tld/app/delete/Model/nn

That is the app name is inserted. Odd. And undesired if not a crisis.

But here's what bamboozles me. I can replace "app" in the url with any string at all, "x" say and the site continues to work but those URLs now point to :

http://mysite.tld/x/list/Model
http://mysite.tld/x/add/Model
http://mysite.tld/x/edit/Model/nn
http://mysite.tld/x/view/Model/nn
http://mysite.tld/x/delete/Model/nn

For what it's worth I don't want to quote urls.py and every other bit of possible config here of course, I am mainly interested to know if someone has insights that aren't shared in that SO link above as none of what is shared there seems to apply.

For anyone really keen on code explorations urls.py is here:

https://github.com/bernd-wechner/CoGs/blob/master/CoGs/urls.py

and the whole site is there too.

What I want to understand is why this "app" suddenly appears in my URLs and how I can control it (remove it ideally). But I have looked at urls.py long enough and scratched my head and not found it. settings.py is right next to if you need to inspect it.

Kind regards,

Bernd.




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c2b971d4-61be-e74f-e6bc-6f3ed8ce2a65%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACOk0Tz1oBdnusZLeyHpcYSsVhSynKNOSsd%3DQdNoHuzQmkWdJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


No comments:

Post a Comment