Django Production Server ModelForm help_texts

时间:2015-05-16 19:07:50

标签: django django-forms

我的生产服务器上发生了一些奇怪的错误。在本地开发服务器上,我的ModelForm帮助文本工作正常,而在生产服务器上,只显示默认的ModelForm帮助文本。

表格:

class ProjectForm(ModelForm):

    class Meta:
        model = Project
        fields = [
            'name',
            'types',
            'origin',
            'start_date',
            'end_date',
            'description',
            'status',
            'tags',
            'notes',
        ]

        widgets = {
            'start_date': forms.DateInput(format='%m/%d/%Y', attrs={'class':'datePicker'}),
            'end_date': forms.DateInput(format='%m/%d/%Y', attrs={'class':'datePicker'}),
        }

        help_texts = {
            'start_date' : 'If you only know the year, enter an approximate start date, such as 01/01/2012',
            'end_date' : 'If you only know the year, enter an approximate start date, such as 01/01/2012',
        }

我已经仔细检查了所有的点数要求,版本都是一样的。我已经重新启动了服务器等。我可以从字段列表中删除一个字段,当刷新页面时,字段将被删除,但仍然没有帮助文本。任何想法?

编辑:

请记住,项目的其余部分工作正常。开发和生产版本之间唯一明显的区别是表单help_text仅显示默认值。

index.wsgi:

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/abercrrl/.virtualenvs/cdh_at/lib/python2.6/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/path/to/cdh_at')
sys.path.append('/path/to/cdh_at/cdh_at')

os.environ['DJANGO_SETTINGS_MODULE'] = 'cdh_at.settings'

#Activate your virtual env
activate_env = os.path.expanduser("/home/abercrrl/.virtualenvs/cdh_at/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

的httpd.conf:

....
WSGIScriptAlias /cdh_at /path/to/cdh_at/cdh_at/index.wsgi

<Directory /path/to/cdh_at/cdh_at/index.wsgi>
Order deny,allow
Allow from all
</Directory>

Alias /cdh_at/static/ /path/to/cdh_at/static/
<Directory /path/to/cdh_at/static/>
Allow from all
</Directory>
.... 

1 个答案:

答案 0 :(得分:0)

也许你的问题是由于国际化,试试这个:

from django.utils.translation import ugettext_lazy as _

help_texts = {
    'start_date' : _('If you only know the year, enter an approximate start date, such as 01/01/2012'),
    'end_date' : _('If you only know the year, enter an approximate start date, such as 01/01/2012'),
}