Problem with create new instance

53 views
Skip to first unread message

Dariusz Mysior

unread,
Mar 9, 2016, 12:48:15 PM3/9/16
to Django users
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']



Dariusz Mysior

unread,
Mar 9, 2016, 1:24:37 PM3/9/16
to Django users
I found that when I write import django and next django.setup() to terminal than it works. But next question, when I put it to automaticly run it...

Dariusz Mysior

unread,
Mar 9, 2016, 1:35:45 PM3/9/16
to Django users
Ok I have it. I put it to starting scripts


W dniu środa, 9 marca 2016 18:48:15 UTC+1 użytkownik Dariusz Mysior napisał:

knbk

unread,
Mar 9, 2016, 2:26:39 PM3/9/16
to Django users
Any reason you're not using `manage.py shell`? It automatically loads the Django environment, and supports IPython. 
Reply all
Reply to author
Forward
0 new messages