Django:渲染打印随机数和0

2024-10-01 11:33:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在在办公室用Django做表格。一切都很好,直到我意识到有任何随机数当我访问网络。你知道吗

592
<html>
    <head>
        <title> Rekonsiliasi | Matching</title>
        <style>
            th{
                text-align: center;
            }
            ul{
                list-style-type: none;
            }
        </style>

因为它是使用Django中的模板呈现的,所以我尝试清空模板文件,但它仍然打印“0”。你知道吗

0

所以,我认为这不是模板的问题。你知道吗

你知道发生了什么事吗?你知道吗

这是相关的python代码。你知道吗

def choose(request,fl):
# fl is a form-name to show
if request.method == 'POST':
    return saving(request,fl)
else:
    return render(request,'rekonsi_db/choose.html',{'file' : fl})

这是我的设置.py你知道吗

 """
Django settings for web 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
# import djcelery
from ConfigParser import RawConfigParser
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 = '#####'

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

TEMPLATE_DEBUG = True

TEMPLATE_DIRS = (
    '####',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

ALLOWED_HOSTS = ['#####','####']

# Database configuration

config = RawConfigParser()
config.read('#####')

DATABASE_USER = config.get('database', 'DATABASE_USER')
DATABASE_PASSWORD = config.get('database', 'DATABASE_PASSWORD')
DATABASE_HOST = config.get('database', 'DATABASE_HOST')
DATABASE_PORT = config.get('database', 'DATABASE_PORT')
DATABASE_ENGINE = config.get('database', 'DATABASE_ENGINE')
DATABASE_OPENMRS = config.get('database', 'DATABASE_OPENMRS')
DATABASE_TEST = config.get('database', 'DATABASE_TEST')
DATABASE_PERSONNEL = config.get('database', 'DATABASE_PERSONNEL')

# Celery

BROKER_URL = '#####'

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    '####',
    '####',
    '####',
    '####',
    'rekonsi_db'
    # 'report',
)

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 = 'web.urls'

WSGI_APPLICATION = 'web.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, 'db.sqlite3'),
    }
}

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Jakarta'

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/'
STATIC_ROOT = '####'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

#MEDIA
MEDIA_ROOT = '####'
MEDIA_URL = '/media/'
FILE_UPLOAD_TEMP_DIR = '#####'
FILE_UPLOAD_MAX_MEMORY_SIZE = 0
# Logging
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '####',
            'formatter': 'verbose'
        },
        'warning': {
            'level': 'WARNING',
            'class': 'logging.FileHandler',
            'filename': '####',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'handlers':['file'],
            'propagate': True,
            'level':'DEBUG',
        },
        'gxp': {
            'handlers': ['file', 'warning'],
            'level': 'DEBUG',
        },
    }
}

这是我的网址.py你知道吗

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

admin.autodiscover()

urlpatterns = patterns('',
    #####
    url(r'^rekonsi_db/$','rekonsi_db.views.settings'),
    url(r'^rekonsi_db/thanks/(\w+)/$','rekonsi_db.views.thanks'),
    url(r'^rekonsi_db/choose/(\w+)/$','rekonsi_db.views.choose'),
    url(r'^rekonsi_db/choose/(\w+)/api_yang_belum$','rekonsi_db.views.api_yang_belum'),   
)

这是模板:

    <html>
    <head>
        <title> Rekonsiliasi | Matching</title>
        <style>
            th{
                text-align: center;
            }
            ul{
                list-style-type: none;
            }
        </style>
        {% load staticfiles %}
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href='{% static "rekonsi/simplePagination.css" %}'>
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        <script src='{% static "rekonsi/index.js" %}'></script>
    </head>
    <body>
        <div class='container'>
            <div class='col-md-4'></div>
            <div class='col-md-4' style='font-size : 14pt; text-align : center; margin : 4px;'> <h1>Rekonsiliasi Data</h1></div>
            <div class='col-md-4'></div>
        </div>
        <form role='form'  method='POST' class='form-group'>
            {% csrf_token %}
            <p hidden id='file_name'>{{file}}</p>
            <div id='choosing' class='container' style='width:100%;'>
            </div>
            <input type='submit' id='submit'>
        </form>
    </body>
</html>

感谢您的帮助。我用的是django1.6 (更新:这发生在整个django项目上)


Tags: djangohttpsdivcomconfigdbgetsettings
1条回答
网友
1楼 · 发布于 2024-10-01 11:33:16

事实上,后来,我试着运行其他django项目,我有同样的情况。你知道吗

我试图重新启动我的笔记本电脑,再次运行这个项目(以及其他),打印的大小已经消失。你知道吗

但还是不知道原因。你知道吗

不管怎样,谢谢大家的参与!你知道吗

相关问题 更多 >