RemovedInDjango19Warning - isn't in an application in INSTALLED_APPS - python

I am getting the following error when importing the models module in Django.
/Users/markcollier/Documents/Adapt/Taboo/TabooAPI/env/lib/python2.7/site-packages/django/contrib/contenttypes/models.py:161: RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class ContentType(models.Model):
I have searched around and tried all of the suggested solutions to similar problems.
I think it has something to do with how my settings.py file is set up but could be wrong. All help would be much appreciated.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'api.apps.ApiConfig',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'api.permissions.IsOwner',
)
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
apps.py
from __future__ import unicode_literals
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'
directory structure:
django_api
api
__init__.py
apps.py
migrations
models.py
permissions.py
serializers.py
signals.py
temp.py
urls.py
views.py
datasets
django_site
__init__.py
settings.py
urls.py
wsgi.py
db.sqlite3
manage.py

According to the error message you posted, the problem is not with your own app but with django.contrib.django.contenttypes.models.ContentType - and googling for this exact error message shows you're not the first having this issue.
Since contenttypes is in your installed apps, the problem comes from contenttype being imported before being "officialy" loaded. So what you need know is to find out where contenttype is imported and which of these imports happens too soon - or just first try to place it first in your settings INSTALLED_APPS as FeroxTL suggest, it might (or not) solve the problem.

Related

how to solve this problem in virtual environment?

i want to activate my models in my files, my code in terminal:
(env) PS C:\Users\MadYar\Desktop\code.py\learning_log> python manage.py makemigrations learning_logs
error:
No changes detected in app 'learning_logs'
im using django to make a web application and i add models in my settings.py like that:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs'
]
i dont know why it sais no changes detected in app 'learning_logs'
add empty __init__.py in learning_logs folder.
check if you have any models.py in learning_logs folder.
add some models, which inherited from django.models.Model:
from django import models
class MyModel(models.Model):
myfield = models.Charfield(max_length=255)
call python manage.py makemigrations learning_logs
if you see No changes detected in app 'learning_logs' again, try to read the tutorial, especially this part: https://docs.djangoproject.com/en/4.0/intro/tutorial02/

No changes detected in app 'learning_logs'

I ran the code settings.py and went to INSTALLED APPS and added learning_logs:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs',
Then in the terminal I ran 'python manage.py makemigrations learning_logs'
However it results in 'No changes detected in app 'learning_logs'
Note that I read some other articles and got no good answer
Also note that the end bracket is supposed to be in the dictionary
You can try this:
Add __init__.py file into the app folder.
Make sure you have some models classes created in models.py file in the app
Please check your model definition and make sure that it inherits from django models.Model!
from django.db import models
class MyCustomModel(models.Model):
...

Django - makemigrations - No changes detected/Apps could not be found

I was trying to create migrations within an existing app using the makemigrations command but it outputs "No changes detected".
The code I used for that is
python3 manage.py makemigrations
I tried:
python3 manage.py makemigrations polls
and it shows
"App 'polls' could not be found. Is it in INSTALLED_APPS?"
Here is my INSTALLED_APPS of the 'settings.py' file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig',
]
I know some people simply put 'polls', it doesn't work either
Here is my folder structure:
Here is my 'apps.py':
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
Here is my urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('new', views.new),
]
I am using django2.1 and python3.8.

Why does my Django robots.txt works on development but returns server error 500 on production?

I'm trying to create a robots.txt file for my django website following this tutorial
The end result is good on development and everything is working. However, when I pushed the files into production I got a Server Error (500) even though I changed all the 127.0.0.1:8000 into mywebsite's domain.
My settings.py Installed apps looks like this:
INSTALLED_APPS = [
'search.apps.SearchConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'robots',
'django.contrib.sites',
]
My main project's urls.py looks like this:
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("search.urls")),
path("sitemap.xml", sitemap, {'sitemaps': sitemaps}),
path('robots.txt',include('robots.urls')),
]
I installed the django-robots using pip install, and I did the necessary migrations on my production server but it doesn't fix the problem.

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I am using ajax to call the following url:
"https://www.bittrex.com/api/v1.1/public/getticker?market=usdt-btc"
I am getting the following error:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have installed django-cors-headers and my settings.py looks like this:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'crispy_forms',
# The following apps are required:
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'http://127.0.0.1:8000',
)
Why am I still getting the error?
** I have read all the other answers related to this but they have not helped me. I have used the chrome plugin too and it does work with it but I want a solution without it **
Django Version = 1.8
The configuration looks fine and according to the documentation. I just compared it to my configuration and it's almost the same. Since I use my API for only one website, I have it configured in my CORS_ORIGIN_WHITELIST, you can try this also to see if it responds.
Also, try removing all python cache files and restart the application server, maybe the setting where not loaded.
It is not your app issue i.e. django issue as CORS is a http header which let's a user agent gain permission to a resource which is on a different domain as that of yours. It is a browser issue, hence adding CORS application in django will have no effect.
More information here
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Try adding crossDomain: true in the ajax request

Categories