I'm trying to run a server on my computer in Python/Django. In my installed_apps, I had a program called csvimport. It didn't work, so I had to install django-csvimport and I had to change it to csvimport.app.AppConfig in my installed-apps. However, I still get an importerror message saying "no module named AppConfig". (my version of django is 1.8, and django-csvimport is 2.4, by the way) Is this not the correct way to have csvimport in my installed_apps and my program?
Thanks!
AppConfig is Django's base class for the configuration class of custom apps, not necessarily the name of the config class of the app. But you're almost there:
csvimport.app.CSVImportConf
Related
I am trying to make a web application using django. so in the website folder, I made another app named U0.
I made sure to add it in the settings section of the website. but when I try to migrate the manage.py file it throws an error saying, No Module found named U0django
In order to create a new app in Django, you have to use the Django builtin command to create the correct structure of an app for you like this:
django-admin startapp u0
btw I believe if you want to create it on your own you have to create a file named apps.py in your app folder and add these lines to that to help Django identify it as an app :
from django.apps import AppConfig
class U0(AppConfig):
name = 'u0'
Python version : 2.7.10
Django version : 1.8
Environment : Virtual environment
Problem: Whenever i tried to run ./manage.py runserver or shell I get this error
"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."
Based on some responses on some related posts, I have also checked my wsgi file and it has the updated way of referencing the wsgi application. Here's how my wsgi file looks:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "instant_reports.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Any help/guidance on resolving this ?
Did you use ugettext() in your code? Change it to ugettext_lazy().Quoting Django official documentation:
AppRegistryNotReady: This happens when importing an application configuration or a models module triggers code that depends on the app registry.
For example, ugettext() uses the app registry to look up translation
catalogs in applications. To translate at import time, you need
ugettext_lazy() instead. (Using ugettext() would be a bug, because the
translation would happen at import time, rather than at each request
depending on the active language.)
You need to use the lazy translation in your settings.py and any file (views.py, models.py) that might get imported while Django is boostrapped.
I have a Django project that worked well with Django 1.6, but is giving me a lot of trouble as I try to upgrade to Django 1.7.
In this project is an app, my_app which does not contain any models of its own, but contains a file other_models.py, generated to interact with a legacy database using python manage.py inspectdb. I want to use these models only in specific code paths, when I'm connected to a this secondary database. Again, this worked fine with Django 1.6.
Having upgraded to Django 1.7, I am no longer able to run my test suite using python manage.py test. When I do this, I get a huge number of errors that look like the following:
CommandError: System check identified some issues:
ERRORS:
my_app.AccountAccount.created_by_type: (fields.E304) Reverse accessor for 'AccountAccount.created_by_type' clashes with reverse accessor for 'AccountAccount.deactivated_by_type'.
HINT: Add or change a related_name argument to the definition for 'AccountAccount.created_by_type' or 'AccountAccount.deactivated_by_type'.
...
# Tons more of these
These errors are all complaining about models defined in other_models.py. It appears to me that the changes in app-loading process are causing my problems, but I'm not entirely sure.
I have tried setting up an apps.py in this app with the following code:
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = 'my_app'
models_module = None
and added default_app_config = 'my_app.apps.MyAppConfig' to my my_app.__init__.py, as per the documentation on configuring applications, but to no avail.
I'm at a total loss for what to do next, and would appreciate any information regarding how to control when and how Django attempts to load models, especially when running python manage.py test.
Following on from my last question Error: No module named psycopg2.extensions, I have updated my mac OS to Mountain Lion and installed Xcode. I have also installed psycopg2 using 'sudo port install py27-psycopg2'. I am now trying to run 'python manage.py runserver' but am receiving this error
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
Any help on how to fix this and get my localhost running?
From django docs:
A Django settings file contains all the configuration of your Django installation.
When you use Django, you have to tell it which settings you're using.
Do this by using an environment variable, DJANGO_SETTINGS_MODULE.
The value of DJANGO_SETTINGS_MODULE should be in Python path syntax,
e.g. mysite.settings. Note that the settings module should be on the
Python import search path.
And
ROOT_URLCONF
Default: Not defined
A string representing the full Python import path to your root
URLconf. For example: "mydjangoapps.urls". Can be overridden on a
per-request basis by setting the attribute urlconf on the incoming
HttpRequest object. See How Django processes a request for details.
If you are using multiple settings files, be sure to import the base settings in all the other settings files. This was how I got this error.
If you're working on a Django project, the root of your project(ROOT_URLCONF= variable) isn't defined in your settings.py file, or at least it isn't defined properly.
If you don't have a settings.py file, this block of code should fix the issue:
from django.conf import settings
settings.configure(
# ...
ROOT_URLCONF=__name__,
# ...
),
)
What that does is specify the root of your project runserver knows where to find your project.
If do have a settings.py file, then find that variable and add __name__ to it.
I have setup a Django project on my laptop and build my first app. I have setup all the necessary software on a second server and I want to migrate my project to that one.
After uploading my files, I have tried a couple of things, but I still get errors like:
ImportError at /
No module named myapp.models
Request Method: GET
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
No module named myapp.models
Exception Location: /var/www/wsgi/myproject/myapp/admin.py in <module>, line 2
Python Executable: /usr/bin/python
Python Version: 2.6.5
The problematic line on admin.py looks like:
from myapp.models import (...)
and file models.py in this app has the necessary stuff, so I guess it can't resolve the app namespace or something?
It seems your PYTHONPATH doesn't include /var/www/wsgi/myproject. Can you show your WSGI config file?
You may need to move/create an __init__.py file in your app directory.