繁体   English   中英

Django:导入错误; 没有名为 url 的模块

[英]Django : ImportError ; No module named urls

我是一个完整的 Django 初学者,我尝试创建我的第一个 Django 网页,但没有成功,上面只有“Hello world”。 我一直在尝试通过在互联网上查找来解决我的问题几个小时,但没有一个解决方案对我有用。 这是我的代码:我希望我能在这里得到帮助......

这是我的目录树:

./ProjetArbre: AppliPageArbre arbre.db init .py manage.py ProjetArbre

./ProjetArbre/AppliPageArbre: admin.py init .py models.py tests.py views.py admin.pyc init .pyc models.pyc urls.py

./ProjetArbre/ProjetArbre: init .py settings.py urls.py wsgi.py init .pyc settings.pyc urls.pyc wsgi.pyc

这是 ProjetArbre/AppliPageArbre/urls.py :

from django.conf.urls.defaults import patterns,url
from views import home

urlpatterns=patterns('',
    url(r'^home/$',home,name="home")
)

ProjetArbre/AppliPageArbre/views.py :

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request) :
    #return HttpResponse("HelloWorld")
    print 'HelloWorld'

ProjetArbre/urls.py :

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

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

    url(r'^admin/', include(admin.site.urls)),
    url(r'^AppliPageArbre/', include('ProjetArbre.AppliPageArbre.urls')),
)

最后是 ProjetArbre/ProjetArbre/settings.py :

""" Django settings for ProjetArbre project.

For more information on this file, see https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see https://docs.djangoproject.com/en/1.6/ref/settings/ """

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'v%!t3(w*fr)0n_!98=se_o_+@+o2(_0*d0&pu19@z5g1hxz13^'

# SECURITY WARNING: don't run with debug turned on in production! DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'AppliPageArbre', )

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware', )

ROOT_URLCONF = 'urls' #simplement urls ?

WSGI_APPLICATION = 'ProjetArbre.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'arbre.db'),
    } }

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'fr-fr'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

我在http://localhost:8000/AppliPageArbre/home上得到的错误是:

ImportError at /AppliPageArbre/home

No module named urls

Request Method:     GET
Request URL:    http://localhost:8000/AppliPageArbre/home
Django Version:     1.6
Exception Type:     ImportError
Exception Value:    

No module named urls

Exception Location:     /home/eisti/Dev/Environnement/local/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable:  /home/eisti/Dev/Environnement/bin/python
Python Version:     2.7.12
Python Path:    

['/home/eisti/Dev/ProjetArbre',
 '/home/eisti/Dev/Environnement/lib/python2.7',
 '/home/eisti/Dev/Environnement/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/eisti/Dev/Environnement/lib/python2.7/lib-tk',
 '/home/eisti/Dev/Environnement/lib/python2.7/lib-old',
 '/home/eisti/Dev/Environnement/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/eisti/Dev/Environnement/local/lib/python2.7/site-packages',
 '/home/eisti/Dev/Environnement/lib/python2.7/site-packages']

Server time:    jeu, 19 Jan 2017 18:29:34 +0100

我正在使用 Django 1.6 提前感谢您的帮助...

我通过阅读关于 Django 1.10 的另一个教程设法解决了这个问题。 谢谢 :)

现在,我有另一个问题:在models.py 中,我有以下类,例如:

class Profil(models.Model):
    sexe = models.CharField(max_length=1, choices=genre_choix,default="N")
    id_profil = models.AutoField(auto_created=True, primary_key=True, serialize=False)
    famille = models.ForeignKey(Famille, default=0, blank=True,unique=False,null=True)
    prenom = models.CharField(max_length=30)
    prenom2 = models.CharField(max_length=30,blank=True)
    nom_famille = models.CharField(max_length=30)
    nom_jeune_fille = models.CharField(max_length=30,blank=True)
    Date_anniv = models.DateField(blank=True, null=True)
    mort = models.DateField(blank=True, null=True)
    travail = models.CharField(max_length=25, default="", blank=True)
    information = models.TextField(default="", blank=True)
    profil_picture = models.FileField(blank=True)

    def __str__(self):
        return str(self.prenom)



class Couple(models.Model):
    p1 = models.ForeignKey("Profil", related_name='+')
    p2 = models.ForeignKey("Profil", related_name='+')
    marriage = models.DateField(default="", blank=True,null=True)
    divorce = models.DateField(default="", blank=True,null=True)

    def __str__(self):
        return str(self.p1.prenom+"<3"+self.p2.prenom)

我希望每次创建新配置文件时,都会创建一对情侣,其中 p1 = 我刚刚创建的配置文件,而 p2 = 带有“?”的虚假配置文件。 而不是名字。 但是,由于两个外键,我不知道该怎么做...

暂无
暂无

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

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