Reputation: 351
I am new to Django and was learning about views and urls. This is from the official Django documentation.
urls.py ->
from django.conf.urls import url
from . import views
urlpatterns = [
# ex: /polls/
url(r'^$', views.index, name='index'),
]
views.py ->
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
So if my Django server is running on default port 8000 and if I type the address 127.0.0.1:8000/polls where polls is my app name I will be redirected to a view saying Hello, world. You're at the polls index. I want my server to display a view when I type in the url 127.0.0.1:8000 without the app name. If this is possible, how should I do it?
Upvotes: 0
Views: 1506
Reputation: 1084
You need to add the url(r'^$', views.index, name='index'), to your project's urls.py not in app's urls.py.
Upvotes: 2
Reputation: 1089
you have to change it at the main urls.py
. This file is maybe in the mysite
folder. So change
url(r'^polls', include('polls.urls')),
to
url(r'^', include('polls.urls')),
Upvotes: 3