Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8169123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:45:09+00:00 2026-06-06T20:45:09+00:00

Folder Structure I’m currently learning Django from the Django book. I have the following

  • 0

Folder Structure

I’m currently learning Django from the Django book. I have the following directory structure:

.
└── mysite
    ├── books
    │   ├── __init__.py
    │   ├── models.py
    │   ├── templates
    │   │   ├── search_form.html
    │   │   └── search_results.html
    │   ├── tests.py
    │   └── views.py
    ├── contact
    │   ├── forms.py
    │   ├── __init__.py
    │   ├── templates
    │   │   └── contact_form.html
    │   └── views.py
    ├── manage.py
    └── mysite
        ├── __init__.py
        ├── settings.py
        ├── templates
        │   ├── base.html
        │   ├── current_datetime.html
        │   └── hours_ahead.html
        ├── urls.py
        ├── views.py
        └── wsgi.py

Where books, contact, and mysite are folders. I also have a separate templates subfolder for each of those folders to store templates.

Story

Now, inside /mysite/settings.py, I have the following lines:

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/'),
)

Inside /contact/views.py, I have the following line (note that render here is from django.shortcuts):

return render(request, 'contact_form.html', {'form': form})

However, the line above gives me a TemplateDoesNotExist exception. This is because the template loader looks for the file contact_form.html under /mysite/templates/ instead of /contact/templates/.

Fair enough, even though I don’t understand why that’s the case. But, I have another case where it behaves differently.

Recall in the file structure above, I also have books/views.py. In it, I have the following lines (in different logical blocks):

return render(request, 'search_results.html',
                {'books': books, 'query': q})

and

return render(request, 'search_form.html', {'errors': errors})

If you look back above, search_results.html and search_form.html are under the /books/templates/ folder, not /mysite/templates/ folder, and yet the template loader managed to find those files. Note that it still works even when I move search_results.html and search_form.html into /mysite/templates/.

So my question is, why is there a difference in where the loader looks for templates?

Files

Anyway, here’s what my /contact/views.py looks like:

from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from forms import ContactForm
import os

def contact(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail(
                    cd['subject'],
                    cd['message'],
                    cd.get('email', 'noreply@example.com'),
                    ['siteowner@example.com'],
            )
            return HttpResponseRedirect('/contact/thanks/')
    else:
        form = ContactForm()
    print os.path.join(os.path.dirname(__file__), 'templates')
    return render(request, 'contact_form.html', {'form': form})

Here’s my /books/views.py:

from django.shortcuts import render
from django.http import HttpResponse
from books.models import Book


def search(request):
    errors = []
    if 'q' in request.GET:
        q = request.GET['q']
        if not q:
            errors.append('Enter a search term.')
        elif len(q) > 20:
            errors.append('Please enter at most 20 characters.')
        else:
            books = Book.objects.filter(title__icontains=q)
            return render(request, 'search_results.html',
                {'books': books, 'query': q})
    return render(request, 'search_form.html', {'errors': errors})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:45:11+00:00Added an answer on June 6, 2026 at 8:45 pm

    Since you apparently do have the app directories template loader installed, and since it works on your books app, I can only conclude you don’t have contact in settings.INSTALLED_APPS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following folder structure in python: houses/ models.py __init__.py view/ houses.py events.py
I have the following folder structure for the templates on my django app: templates/
Suppose I have the following (desired) folder structure: *CommonProject *Project#1 ----> CommonProject(link) *Project#2 ---->
I have got following folder structure for my domain (domain.com): /data/images (it´s subdomain name,
I have following folder structure: ProjectFolder/images/some images In the same folder ProjectFolder/WEB-INF/classes/com/xyz/here is java
I have the following folder structure to my nodeunit tests for a particular project:
I have the following folder structure: FolderA --Folder1 --Folder2 --Folder3 ... --Folder99 Folders 1
I have this folder structure: package/ __init__.py misc/ __init__.py tools.py subpackage/ __init__.py submodule.py I
how to hide folder structure of website from users. i have developed a website
I have the following folder structure TempProj !-js !-jsp !-WEB-INF !-classes !-lib Inside my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.