简体   繁体   English

Django“ /处的导入错误”

[英]Django “ImportError at /”

I am getting an import error on a very basic test site I am trying. 我在一个非常基本的测试站点上遇到导入错误。 Below is the error message: 下面是错误消息:

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

My directory structure is this: 我的目录结构是这样的:

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

Under dcdev1 there are __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc 在dcdev1下有__init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc

Under tickets there are 门票下有

__init__.py __init__.pyc models.py models.pyc templates tests.py views.py views.pyc __init__.py __init__.pyc models.py models.pyc templates tests.py views.py views.pyc

Relevant settings.py sections: 相关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: 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: 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 views.py

from django.shortcuts import render_to_response

from tickets.models import ticket_info

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

I am working off of the guide at http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/ 我正在使用位于http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/的指南

There seems to be some differences in his directory structure vs mine. 他的目录结构与我的目录结构似乎有些差异。 I'm guessing something had changed in later django versions. 我猜在django的更高版本中发生了一些变化。 I have never used django, just trying it out to see if it will work for a project. 我从来没有使用过django,只是尝试过看看它是否对项目有用。 Any help would be much appreciated. 任何帮助将非常感激。

In urls.py try these 在urls.py中尝试这些

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

instead of these 代替这些

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

Also you can run python manage.py validate and maybe you will see something useful. 您也可以运行python manage.py validate ,也许您会看到有用的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM