ImportError: No module named site

1,016 views
Skip to first unread message

Kyle Latham

unread,
Jun 29, 2011, 1:32:32 PM6/29/11
to Django users
I searched this group for that error, and browsed through several
pages and dozens of posts...but none of them helped me solve my error.

Yesterday I had my server up and running, and I left it running
overnight. I do not remember changing anything in any of my .py files,
but when I shut down my server to restart it, I was getting an error:

"Import Error: No module named site"

I have no idea what is going wrong, but here is all my code thus far
(I'm following the tutorial to create my own app that will display
various material measurements)

-----------------------------------------------
models.py
-----------------------------------------------
from django.db import models

# Create your models here.
class adhesive(models.Model):
measurement_id = models.CharField(max_length = 200)
material_id = models.CharField(max_length = 200)
program_name = models.CharField(max_length = 200)
date = models.DateField()
measurement_method = models.CharField(max_length = 30)
frequency_low = models.IntegerField()
frequency_high = models.IntegerField()

class ceramic(models.Model):
measurement_id = models.CharField(max_length = 200)
material_id = models.CharField(max_length = 200)
program_name = models.CharField(max_length = 200)
date = models.DateField()
measurement_method = models.CharField(max_length = 30)
frequency_low = models.IntegerField()
frequency_high = models.IntegerField()

class composite(models.Model):
measurement_id = models.CharField(max_length = 200)
material_id = models.CharField(max_length = 200)
program_name = models.CharField(max_length = 200)
date = models.DateField()
measurement_method = models.CharField(max_length = 30)
frequency_low = models.IntegerField()
frequency_high = models.IntegerField()


---------------------------------------------------
settings.py
---------------------------------------------------
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add
'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'materials', # Or path to
database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'xxxxx', # Not used with sqlite3.
'HOST': '', # Set to empty string for
localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for
default. Not used with sqlite3.
}
}

...

ROOT_URLCONF = 'material_measurements/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.
"C:/Django/material_measurements.materials"
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'material_measurements.materials',
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)




---------------------------------------
urls.py
---------------------------------------
from django.conf.urls.defaults import *

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

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'material_measurements.views.home', name='home'),
# url(r'^material_measurements/',
include('material_measurements.foo.urls')),

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

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





Thanks for the help!

Andre Terra

unread,
Jun 29, 2011, 9:26:34 PM6/29/11
to django...@googlegroups.com
As you can see from your urls.py, there is a reference to admin.site
and that is probably what's not working on your setup.

Try this:
$ ./manage.py shell
>>> import django
>>> django.get_version()
>>> from django.contrib import admin
>>> admin.site

..and see how far you can go before the first exception. Feel free to
paste the results in a reply.

Sincerely,
André Terra

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

--
Sent from my mobile device

bruno desthuilliers

unread,
Jun 30, 2011, 4:54:30 AM6/30/11
to Django users
On Jun 29, 7:32 pm, Kyle Latham <kly.lat...@gmail.com> wrote:
(snip)
Totally unrelated to your question, but: why on earth are you creating
3 distincs models with the exact same fields ??? You just need one
single model, and add a "material_type" field (eventually passing in a
choices list of "Composite", "Ceramic" and "Adhesive").

Also and while we're at it, the naming convention in Python is to use
MixedCase for class names. Better to follow the established
conventions....

Andy Dustman

unread,
Jun 30, 2011, 10:27:27 AM6/30/11
to django...@googlegroups.com

Another possibility is to make a Material abstract base class, and
have Adhesive, Ceramic, and Composite inherit from it. Or, have a
non-abstract Material base class. Doing either of these things really
only makes sense if you have extra fields to add to the subclasses. I
tend to think doing what Bruno suggests (adding a material type field)
will work better.

Reference; https://docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance

--
Question the answers

Reply all
Reply to author
Forward
0 new messages