My app contact. I have model and form like below and when I run command
from contact.forms import MessageFormand next
form = MessageForm()
In[2]: from contact.forms import MessageForm
In[3]: form = MessageForm()
Traceback (most recent call last):
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 161, in _add_installed_apps_translations
app_configs = reversed(list(apps.get_app_configs()))
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/IPython/core/interactiveshell.py", line 3066, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-f0946f215028>", line 1, in <module>
form = MessageForm()
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/forms/models.py", line 329, in __init__
error_class, label_suffix, empty_permitted)
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/forms/forms.py", line 129, in __init__
self.label_suffix = label_suffix if label_suffix is not None else _(':')
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 84, in ugettext
return _trans.ugettext(message)
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 317, in gettext
return do_translate(message, 'gettext')
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 300, in do_translate
_default = _default or translation(settings.LANGUAGE_CODE)
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 206, in translation
_translations[language] = DjangoTranslation(language)
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 116, in __init__
self._add_installed_apps_translations()
File "/home/darek/.virtualenvs/kurs/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 164, in _add_installed_apps_translations
"The translation infrastructure cannot be initialized before the "
django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
from django.db import models
# Create your models here.
class Message(models.Model):
name = models.CharField(max_length=250)
email = models.EmailField()
message = models.TextField()
def __str__(self):
return "message from {name}".format(name=self.name)
#!/usr/bin/env python
from django import forms
from .models import Message
class MessageForm(forms.ModelForm):
class Meta:
model = Message
fields = ['name', 'email', 'message']