Wednesday, March 9, 2016

Problem with create new instance

I have Django 1.8 Python 3.4

My app contact. I have model and form like below and when I run command
 
from contact.forms import MessageForm
 and next
form = MessageForm()

I have error

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.

models.py
 
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)



forms.py

#!/usr/bin/env python
from django import forms
from .models import Message

class MessageForm(forms.ModelForm):
   
class Meta:
        model
= Message
        fields
= ['name', 'email', 'message']



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/38123445-2b27-489b-8029-fa591aa5091b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment