This is a Django site, migrated to Dotcloud through this documentation. I have an issue with my URLs: I cannot access my admin part, and the root URL that is not supposed to be matched matches ! Let me explain in detail:
root/
|- settings.py
|- urls.py
|- champis/
|- urls.py
File root/urls.py:
urlpatterns = patterns('',
(r'^champis/', include('champis.urls')),
(r'^admin/$', include(admin.site.urls)),
)
File root/champis/urls.py:
urlpatterns = patterns('champis.views',
url(r'^$', 'index'),
url(r'^recherche/$', 'search'),
url(r'^glossaire/$', 'glossary'),
url(r'^glossaire/(?P<letter>\w)/$', 'glossary'),
url(r'^(?P<champi_name>\w+)/$', 'detail'),
url(r'^(?P<champi_name>\w+)/(?P<photo_nb>\d+)/$', 'detail'),
)
So I should find my admin site at http://server.com/admin, and my application at http://server.com/champis, but this is not the case:
http://server.com/admin and http://server.com/champis trigger a 404
but my applications is served at http://server.com !
It looks like as if the champis part of the URL was automatically and magically added to the root URL... Do you have an explanation ? Thanks !
EDIT: extract of my settings.py:
ROOT_URLCONF = 'urls'
Django version is 1.4, and actually DEBUG is set to True.
Remove the $ from '^admin/$':
urlpatterns = patterns('',
(r'^champis/', include('champis.urls')),
(r'^admin/', include(admin.site.urls)),
)
Related
Say I have a URL setup like this in my Django 1.6 project:
urlpatterns = patterns('',
url(r'^some-path/', include('someapp.urls')),
url(r'^$', RedirectView.as_view(url='some-path/', permanent=False)),
)
…but I want to change "some-path" to "changed-path" instead, and in the process realize that I've got it hardcoded in an extra place: the RedirectView setup!
Is there a proper way to do something like this, reversing to an included bundle of URLs?
# NOT WORKING! Django ignores `name=` when using `include()`
urlpatterns = patterns('',
url(r'^changed-path/', include('someapp.urls'), name='foo'),
url(r'^$', RedirectView.as_view(pattern_name='foo', permanent=False)),
)
First of all, you have to go to your urls.py file from someapp and get the name of your base url.
Let's assume it's something like:
# someapp/urls.py
urlpatterns = patterns(
'someapp.views',
url(r'^$', 'your view', name='foo'),
...
)
And now in your main urls file, you can write everything like this:
# WORKING! Because Django likes namespaces
urlpatterns = patterns('',
url(r'^changed-path/', include('someapp.urls', namespace='bar')),
url(r'^$', RedirectView.as_view(pattern_name='bar:foo', permanent=False)),
)
I would like to translate URL prefix and also URL slug using django-modeltranslation where slug is saved inside database table. After switching the language i would like to stay on the same page and just change the language. I'm using form language switcher as described here:
http://docs.djangoproject.com/en/dev/topics/i18n/translation/#the-set-language-redirect-view
Problem is that the language is just switching on homepage. The other pages are just refreshed without language and URL change.
Is there any way how can i get current url in other language?
In root project urls.py i have following:
urlpatterns = patterns('',
# Examples:
(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^$', 'portfolio.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns += i18n_patterns('',
url(_(r'^projects/'), include('projects.urls', namespace='projects')),
)
in app called projects i have urls :
urlpatterns = patterns('',
url(r'^$', all_projects, name='projects'),
url(r'^(?P<slug>[\w-]+)/$', project_detail, name='project_detail'),
)
If this is not a copy-paste-problem you're missing url function name in your main urls.py. Change line 3 of your provided code above to:
urlpatterns = patterns('',
...
# The following line need to be changed from
# (r'^i18n/', include('django.conf.urls.i18n')),
# to
url(r'^i18n/', include('django.conf.urls.i18n')),
...
)
I am using Django non-rel in Google App Engine, and my URLConf seems not to work and generate a 500 Server Error.
This is my urls.py file at the root of my app :
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^home/', include('appname.home.urls')),
)
And this is my urls.py in a subpackage home of appname:
from django.conf.urls import patterns, include, url
urlpatterns = patterns(r'appname.home.views',
url(r'^0/', 'home'),
)
It works great in development server but it does not work on Google App Engine.
I already read a related question and its answer but it did not solve my problem.
What does the error message say in the logs? You urlpatterns is malformed. The first r'' is incorrect. That should be a string. And, is the 0 in your url intentional? Change to:
urlpatterns = patterns('appname.home.views',
url(r'^$', 'home'), # matches mysite.com
url(r'^0/$', 'home'), # matches mysite.com/0/
)
Hello and thank you in advance,
When I installed django-profiles and django-registration. I believe I followed a tutorial correctly on how to configure them:
http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps
Now when I try to access website.com/accounts I get a 404 page:
Using the URLconf defined in acme_p.urls, Django tried these URL patterns, in this order:
^$
^accounts/
^admin/doc/
^admin/
The current URL, accounts, didn't match any of these.
My urls files look like this:
#acme_p urls - Django Project
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('user_prof.urls')),
# Examples:
# url(r'^$', 'acme_p.views.home', name='home'),
# url(r'^acme_p/', include('acme_p.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
user_prof urls.py - Django App one level below project mentioned above
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'auth.views.login_user'),
(r'^accounts/', include('registration.urls')),
# (r'^accounts/', include('registration.backends.default.urls')),
)
Thank you for you help.
dp
(r'^accounts/', include('registration.urls')), should be in the root urls.py not the app urls.py
There is no website.com/account in the configuration, there is only website.com/account/(more) where (more) has the rest of the url that is given to the django-registration module. You could try website.com/account/login/ for example to check if the django-registration module is working.
Also you should just put those on the root urls.py file.
In one application's urls.py I have:
urlpatterns = patterns('app.views',
url(r'^products/$', products, name="products"),
url(r'^$', index, name="index"),
)
In base project urls.py I have:
urlpatterns = patterns('',
(r'^$', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
Why http://127.0.0.1:8000/ - works fine with app.views.index method
while http://127.0.0.1:8000/products/ - returns 404 error and is not defined in url routes?
Spent some time on it already and can't find solution, maybe there is something simple that I miss...
Your base urls should be:
urlpatterns = patterns('',
(r'^', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
The '$' is only used for urls. If you look at the doc, it will tell you not use the '$' when using include().
urlpatterns = patterns('',
(r'^', include('app.urls')),
(r'^admin/', include(admin.site.urls)),
)
worked fine.
I was having the same issue while using path() in Django URLs.
The simple fix is you don't have to use the slash at the end of the path otherwise Django will take that URL as a complete URL and will not go to the next urls.py file
//this will not work
path('/', include('app.urls'), name='profile_page')
// but this will work
path('', include('app.urls'), name='profile_page')