Reputation: 8727
I am trying to write a program by running Django using manage.py runserver ip:port in my Linux box as a non-root user. My first objective is that if a user enters a URL in the browser http://ip:port it should display something or a welcome content.
So I modified my mysite/url.py something like this:
urlpatterns = patterns('',
('', ''),
(r'^admin/', include(admin.site.urls)),
)
python manage.py runserver : runs and start fine but in browser I get below exception:
Exception Type: ImproperlyConfigured Exception Value: Empty URL pattern view name not permitted (for pattern '')
So how can construct the URL just like:
www.google.com
www.mail.yahoo.com
www.mysite.com
Thanks in advance
Upvotes: 4
Views: 516
Reputation: 2114
Unless you're willing to get down to the nitty-gritty and configure, run, and host your own Apache Server (or another server config) AND register a domain name, you CANNOT change the domain name from within Python/Django.
Django only handles everything that comes after the domain name, such as the /home/
portion of the URL http://www.mysite.com/home/
.
If you're up to it, the Django book has a pretty good section on deploying Django and setting up the server to run it, but it doesn't cover all the bases.
Upvotes: 3
Reputation: 46233
The empty pattern will match anything, so you should be anchoring it to full empty string. The second tuple parameter must also be a view name.
In your URLconf:
urlpatterns = patterns('',
(r'^$', 'views.home'), # ^$ means, beginning of string followed by end of string, in other words match on exactly empty string and nothing else
(r'^admin/', include(admin.site.urls)),
)
In a views.py
in the same directory:
from django.http import HttpResponse
def home(request):
return HttpResponse('Hello World')
Upvotes: 4