2

Trying to figure out how to setup my own project.

I created a new Django app to make a homepage.

src/home/urls.py:

from django.conf.urls import url

urlpatterns = [
    url(r'^$', 'views.index', name='index'),
]

src/home/views.py:

from django.shortcuts import render
# Create your views here.
def index(request):
    return render(request, "index.html", {})

src/project/urls.py:

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^', include('home.urls')),
    url(r'^admin/', admin.site.urls),
]

src/templates/index.html:

<h1>Hello World</h1>

The reason this isn't in a templates folder inside of the home app is because I want to use this as my base template eventually for all apps and pages

Error reads:

ImportError at /
No module named 'views'

Using python 3.5 and django 1.9

EDIT*** changed to home.views.index

ERROR now reads:

TemplateDoesNotExist at /
index.html

2 Answers 2

3

In Site-wide Urls.py do the Following:

from app_name import urls as app_name_urls
from django.conf.urls import include

urlpatterns=[
path('',include(app_name_urls)
]

In App/urls.py

from django.urls import path
from .import views
urlpatterns=[
    #your paths go here
]
Sign up to request clarification or add additional context in comments.

Comments

2

Make sure you home is a package and you have __init__.py there.

You might also need to change views.index to home.views.index in your urls.py

6 Comments

@SierraKilo Change views.index to home.views.index as @alecxe suggested.
@selcuk now I get a different error saying the template doesn't exist .
Then your template loader is not configured correctly. Update your question to include your settings.py so that we can diagnose.
@SierraKilo you might need to tweak the TEMPLATES setting.
THANKS!!! 'DIRS': [os.path.join(BASE_DIR, "templates")], But does this mean I cant have templates inside my other apps later? Will it always look here for them now? or does will it look inside the app first, and then here?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.