LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2010, 04:06 AM   #1
Shh226
LQ Newbie
 
Registered: Mar 2010
Posts: 8

Rep: Reputation: 0
Question on Django: Deploying on a production server Cannot find templates.


Hello, I seem to have a problem with deploying Django on a production server using Apache. For those who don't know, Django is a is a web framework written in python coding and some html.

I seem to get this error - 'TemplateDoesNotExist at /" "/' .so for any url that requires a template. The other url seem to work fine e.g. (admin & admin/doc works because it does not require a template).

The strange thing is when I use Django Development server python manage.py runserver, The Django runserver can find the templates without any problem. I don't understand what the problem is.

Here are some addition coding

settings.py
PHP Code:
# Django settings for mysite project.

DEBUG True
TEMPLATE_DEBUG 
DEBUG

ADMINS 
= (
    (
'Shehzad Hussain''shehzad@c2duo.com'),
    
# ('Your Name', 'your_email@domain.com'),
)

MANAGERS ADMINS

DATABASE_ENGINE 
'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME 'booksdb'             # Or path to database file if using sqlite3.
DATABASE_USER 'shehzad'             # Not used with sqlite3.
DATABASE_PASSWORD 'arsenal'         # Not used with sqlite3.
DATABASE_HOST 'localhost'             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT '3306'             # Set to empty string for default. Not used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE 'America/London'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE 'en-us'

SITE_ID 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT '/var/www/html/mysite'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL '/html/mysite'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY '@q&b$h$$2fm_bloj^uj(x#oio-mba@%@26(-kx#(oqs4%qqvi4'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    
'django.template.loaders.filesystem.load_template_source',
    
'django.template.loaders.app_directories.load_template_source',
#   'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
   
'django.middleware.common.CommonMiddleware',
   
'django.contrib.sessions.middleware.SessionMiddleware',
   
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF 'mysite.urls'

TEMPLATE_DIRS = (
    
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    
'/var/www/html/mysite/templates',
    
'/var/www/html/mysite/templates/template_projects',
)

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.admindocs'
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.books',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    
'django.core.context_processors.auth',
    
'django.core.context_processors.debug',
    
'django.core.context_processors.i18n',
    
'django.core.context_processors.media',
)

EMAIL_HOST 'shehzad@c2duo.com'
EMAIL_HOST_PASSWORD 'arsenal'
EMAIL_HOST_USER 'shehzad'
EMAIL_PORT '8080' 
urls.py
PHP Code:
from django.conf.urls.defaults import *
from django.views.generic import list_detail
from mysite
.books.models import PublisherBook
from django
.conf import settings
#from mysite.views import requires_login, my_view1, my_view2, my_view3

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin
.autodiscover()

publisher_info = {
    
'queryset' Publisher.objects.all(),
    
'template_name''publisher_list_page.html',
    
'template_object_name''publisher',
    
"extra_context" : {"book_list" Book.objects.all},
}

book_info = {
    
"queryset" Book.objects.order_by("-publication_date"),
}
apress_books = {
    
"queryset"Book.objects.filter(publisher__name="Apress Publishing"),
    
"template_name" "apress_list.html"
}

urlpatterns patterns('mysite.views',
    (
'^hello/$''hello'),
    (
'^time/$','current_datetime'),
    (
r'^time/plus/(\d{1,2})/$','hours_ahead'),
    (
r'^publishers/$'list_detail.object_listpublisher_info),
    (
r'^books/$'list_detail.object_listbook_info),
    (
r'^books/apress/$'list_detail.object_listapress_books),
#    (r'^foo/$', views.foo_view),
#    (r'^bar/$', views.bar_view),
    
(r'^search-form/$''search_form'),
    (
r'^search/$''search'),
    (
r'^contact/$''contact'),


    
# Example:
    # (r'^mysite/', include('mysite.foo.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
     
(r'^admin/doc/'
include(
'django.contrib.admindocs.urls')),

    
# Uncomment the next line to enable the admin:
     
(r'^admin/', include(admin.site.urls)),

and in apache2 httpd.conf
PHP Code:
LoadModule python_module /usr/local/apache2/modules/mod_python.so

<Location "/mysite">
    
SetHandler python-program
    PythonHandler django
.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite
.settings
    SetEnv PYTHON_EGG_CACHE 
/tmp
    PythonOption django
.root /mysite
    PythonDebug On
    PythonPath 
"['var/www/html', '/var/www/html/mysite']+ sys.path
</Location> 
PHP Code:
Template-loader postmortem

Django tried loading these templates
in this order:

    * 
Using loader django.template.loaders.filesystem.load_template_source:
          
/var/www/html/mysite/templates/current_datetime.html (File does not exist)
          
/var/www/html/mysite/templates/template_projects/current_datetime.html (File exists)
    * 
Using loader django.template.loaders.app_directories.load_template_source:
          
/usr/lib/python2.4/site-packages/django/contrib/admin/templates/current_datetime.html (File does not exist)
          
/usr/lib/python2.4/site-packages/django/contrib/admindocs/templates/current_datetime.html (File does not exist

Last edited by Shh226; 06-29-2010 at 04:45 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Installing/Configuring/Caching Django on your Linux server LXer Syndicated Linux News 0 06-05-2008 03:00 PM
LXer: Deploying and tuning Django on CentOS LXer Syndicated Linux News 0 04-26-2008 06:00 AM
Anybody know of where to find good (and/or free) Website templates? perry General 6 09-12-2007 04:03 PM
Newbish question on compiling software for a production server jmille34 Linux - Newbie 3 11-06-2006 12:18 PM
where to find some php templates? essoft478 Linux - General 1 11-24-2004 10:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration