我正在尝试将views.py中的模块导入为
from django.shortcuts import render
# Create your views here.
from viewcreator import Builder
import json
def index(request):
a,b=Builder.buildChartJSON()
print(json.dumps(a))
print(json.dumps(b))
return render(request, 'hdfsStats/hdfscharts.html',
{'sourcepoints': a, 'sizepoints': b})
以及我的项目设置如何
为什么我不能在我的视图中导入模块?我不想在models.py中创建这些类。这些类只是为了运行一些计算并返回两个json对象,然后将其提供给我的网页
这是我的settings.py
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.9.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9mxuqginh(vhh*2eu6j58kbq+%+7ql4_pn3k#yf+n96uv0rymq'
# SECURITY WARNING: don't run with debug turned on in production!
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',
'hdfsStats.apps.HdfsstatsConfig'
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
我缺少任何配置吗?
堆栈跟踪
File "XXX:\mysite\hdfsStats\urls.py", l
ine 3, in <module>
from . import views
File "XXX:\mysite\hdfsStats\views.py",
line 5, in <module>
from viewcreator import Builder
ImportError: No module named 'viewcreator'
更新
目前的结构
和我的views.py
来自django.shortcuts导入渲染
# Create your views here.
from .src.viewcreator import Builder
import json
def index(request):
a,b=Builder.buildChartJSON()
print(json.dumps(a))
print(json.dumps(b))
return render(request, 'hdfsStats/hdfscharts.html',
{'sourcepoints': a, 'sizepoints': b})
但现在我
from propreader import ReadProp
ImportError: No module named 'propreader'
基本上,我有四个包
viewcreator
propreader
esconnector
ping
这些包中的类根据这两个文件夹中的属性文件执行一些计算
props
resources
我把它放在与src
文件夹
由于这些是一次性计算,我不想为这些创建模型。在这种情况下,我配置Django项目的正确方法是什么?我需要Django项目来托管一个显示我的计算结果的网页。