[Answered ]-Django hello world not showing

2👍

Your URLs should look like this:

urlpatterns = patterns('',
     url(r'^admin/', include(admin.site.urls)),
     url(r'^', 'blog.views.index'),
)

Note that the index URL you want to work is now wrapped in a url() call. Also, the index URL now follows the admin URL so that urls referencing /admin are handled by the admin URL, not the catch all index URL you’ve defined.

URL handlers work on first match. Your url(r'^') matches EVERYTHING, so doesn’t give a chance for the admin url to work. You should probably change it to url(r'^$') which will match a ‘no-path’ URL, not a ‘every url’. Note the addition of the $ sign, marking the end of a pattern.

Edit:

Ok, now I understand your problem better. What you’re trying to do, is to deploy a django app at a particular server path that requires a prefix in the URL path.

This is what is usually a standard URL:

http://www.example.com/
http://www.example.com/admin/
http://www.example.com/index/

Instead, this is what you’re trying to do:

http://www.example.com/myapp/
http://www.example.com/myapp/admin/
http://www.example.com/myapp/index/

Django usually expects your app to be deployed at the root URL, with no path. The path is used to find which internal django app should handle the request.

There are two ways for you to solve your problem. The first, and what I’d consider the correct way, is to use the sites framework as described here.

The other, is to add the prefix to all of your URLs in urlpatterns like so:

urlpatterns = patterns('',
     url(r'^blog/admin/', include(admin.site.urls)),
     url(r'^blog/$', 'blog.views.index'),
)

But you will also need to remember to add your ‘blog’ prefix to several settings that expect URLs like LOGIN_REDIRECT etc etc.

What you really should do though, is make django work at the URL: mako34.alwaysdata.net and forget the /blog/ altogether, but modifying apache to redirect all requests to mod_wsgi.

Leave a comment