2013-08-05 75 views
2

我在一個非常基本的測試網站我試圖得到一個導入錯誤。以下是錯誤消息:Django的「導入錯誤在/」

ImportError at/

No module named tickets 

Request Method:  GET 
Request URL: http://dcdev1.dcevolve.com/ 
Django Version:  1.5.1 
Exception Type:  ImportError 
Exception Value:  

No module named tickets 

Exception Location:  /usr/lib/python2.6/site-packages/django/utils/importlib.py  in import_module, line 35 
Python Executable: /usr/bin/python 
Python Version:  2.6.6 
Python Path:  

['/home/django/dcdev1', 
'/usr/lib64/python26.zip', 
'/usr/lib64/python2.6', 
'/usr/lib64/python2.6/plat-linux2', 
'/usr/lib64/python2.6/lib-tk', 
'/usr/lib64/python2.6/lib-old', 
'/usr/lib64/python2.6/lib-dynload', 
'/usr/lib64/python2.6/site-packages', 
'/usr/lib/python2.6/site-packages'] 

Server time: Mon, 5 Aug 2013 02:58:39 -0500 

我的目錄結構是這樣的:

-/home/django/dcdev1 
-/home/django/manage.py 
-/home/django/tickets 

在dcdev1有__init__.py__init__.pycsettings.pysettings.pycurls.pyurls.pycwsgi.pywsgi.pyc

在門票還有

__init__.py__init__.pycmodels.pymodels.pyctemplatestests.pyviews.pyviews.pyc

相關settings.py部分:

TEMPLATE_DIRS = (
    "tickets/templates", 
    # 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. 
) 

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'tickets', 
    # 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 import patterns, include, url 
from tickets.models import ticket_info 
# Uncomment the next two lines to enable the admin: 
# from django.contrib import admin 
# admin.autodiscover() 

urlpatterns = patterns('', 
    # Examples: 
    url(r'^$', 'dcdev1.tickets.views.home', name='home'), 
    # url(r'^dcdev1/', include('dcdev1.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: 
    # url(r'^admin/', include(admin.site.urls)), 

models.py:

from django.db import models 


class ticket_info(models.Model): 
    from_address = models.CharField(max_length = 30) 
    to_address = models.CharField(max_length = 30) 
    subject_id = models.CharField(max_length = 100) 
    body_text = models.TextField() 
    recv_timestamp = models.DateTimeField() 

views.py

from django.shortcuts import render_to_response 

from tickets.models import ticket_info 

def home(request): 
    return render_to_response('index.html') 

我在http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/

工作導承的人們似乎在他的目錄結構VS雷一定的差異。我猜測後來的django版本中有些東西發生了變化。我從來沒有使用django,只是試圖看看它是否會爲一個項目工作。任何幫助將非常感激。

+0

什麼是根目錄設置爲?我的猜測是,你可能在'INSTALLED_APPS' – karthikr

+0

指定'django.tickets'試圖更改爲django.tickets後啓動服務器時,我得到一個「導入錯誤沒有名爲門票模塊」。 – cashman04

+0

與問題無關,但「TEMPLATE_DIRS」註釋清楚地告訴您不要使用相對路徑,而是使用相對路徑。 – Wessie

回答

3

在urls.py 嘗試這些

url(r'^$', 'tickets.views.home', name='home'), 

,而不是這些

url(r'^$', 'dcdev1.tickets.views.home', name='home'), 

你也可以運行python manage.py validate,也許你會看到一些有用的東西。