Pycharm manage.py custom commands - django

I'm using PyCharm 2.7.2, which is the latest version to date.
In my settings file for a django project, I used the following lines to configure my INSTALLED_APPS setting variable.
DJANGO_APPS = (
....
)
THIRD_PARTY_APPS = (
'south',
)
LOCAL_APPS = (
'blog',
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PART_APPS + LOCAL_APPS
Now, south's features do not show up on manage.py. How do I run a custom manage.py command to get things working?

PyCharm doesn't understand concatenation for INSTALLED_APPS, there is an issue logged about it:
PY-8413 PyCharm settings.py parser should understand concatenation in INSTALLED_APPS initialization

Pycharm itself supports running south management commands. See relevant issue.
Looks like pycharm doesn't understand the structure of your project. Recheck if you configured it correctly.

Related

Pyforms web sample now working, only django's default site showing up

I'm trying to follow along with the example shown here: https://pyforms-web.readthedocs.io/en/v4/getting-started/first-app.html to get the first app running.
The Directory Structure of the default Django app looks like that.
I added the code as in the example, ran migrate and opened the brower, but only the default Django page shows up.
My site_crawl.py looks like this:
from pyforms.basewidget import BaseWidget
from confapp import conf
class SiteCrawlApp(BaseWidget):
UID = 'site-crawl-app'
TITLE = 'Site crawl'
LAYOUT_POSITION = conf.ORQUESTRA_HOME
ORQUESTRA_MENU = 'left'
ORQUESTRA_MENU_ICON = 'browser'
ORQUESTRA_MENU_ORDER = 0
The settings.py looks like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'project',
]
Those are the only changes I made to the default structure created when I ran django-admin startproject project also ran python manage.py migrate before starting the web server with python manage.py runserver.
I'm using Python 3.6.0, Django 2.1.7 and Pyforms v4.
Can somebody help me figure out what I'm doing wrong? Thanks!

django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: thumbnail

I am developing a django web project that uses the following packages/applications:
sorl-thumbnail
django-oscar
Here is a snippet of my settings.py file:
INSTALLED_APPS = [
'registration', #should be immediately above 'django.contrib.auth'
'django.contrib.auth',
# ...
'zinnia',
'zinnia_tinymce',
'sorl.thumbnail',
'embed_video',
# ...
'django.contrib.flatpages',
'compressor',
'widget_tweaks',
] + get_core_apps()
When I comment out sorl.thumbnail, I am able to run the development server using manage.py runserver. However, if I uncomment the sorl.thumbnail line and try to run the development server, it throws an exception:
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: thumbnail
Now, I am aware that a similar question exists on this site, however, following the instructions in the accepted solution, i.e.:
create a sol_thumbnail folder in same directory as the manage.py script
create sorl_thumbnail/apps.py (see below)
modify myproject/mysite/___init____.py (see below)
sorl-thumbnail/apps.py
from django.apps import AppConfig
class SorlthumbnailConfig(AppConfig):
name = 'sorl-thumbnail'
label = 'sorl.thumbnail'
myproject/mysite/_init _.py
default_app_config = 'sorl-thumbnail.apps.SorlthumbnailConfig'
Why is the fix above not working, and how do I resolve this issue?
BTW: I am using django-1.10
I went though the same problem of duplicated applications, and following exactly the similar question I solved my problem.
The problem with your solution is that you have added default_app_config = 'sorl-thumbnail.apps.SorlthumbnailConfig' to myproject/mysite/___init____.py, but you should have added to myproject/sorl-thumbnail/___init____.py.

RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

I am building an application with Django Rest Framework and AngularJs. I am using Django-rest-auth for my authentication purposes, although, I have not been able to set it up. Anyway, I am trying to set up this app with my project. I realized I need to install django-rest-auth-registration to get it running, so I followed this documentation to do the following things:
I ran the commands
pip install django-rest-auth
and
pip install django-allauth
Any 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',
# 3rd party apps
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.account',
'rest_auth.registration',
# My app
'myapp',
]
I have also added the authentication backends, context_processors, and the proper urls.
However, when I try to migrate, my terminal throws the following error:
RuntimeError: Model class django.contrib.sites.models.Site doesn't
declare an explicit app_label and isn't in an application in
INSTALLED_APPS.
Why do I get this error, and how do I solve it to migrate my project? Thanks!
The fix
Just add Django's Sites framework to your apps and set SITE_ID to 1 in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
]
SITE_ID = 1
Why does this happen?
Django's Sites Framework is a contributed module bundled with the core library that allows for the use of a single Django application/codebase with different sites (that can use different databases, logic in views, etc). The SITE_ID setting, as stated in the docs, "is used so that application data can hook into specific sites and a single database can manage content for multiple sites."
In this particular case AllAuth requires the Sites Framework in order to function properly. Many other third-party libraries are built to safely handle cases where multiple sites may be present and as such may be best .
I landed on this post via Google search. My problem was running tests that blew up with the error:
RuntimeError: Model class app.taxonomy.models.Term doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
This was running on Python 2.7.x with absolute imports. As mentioned by Colton Hicks in the comments, below, this can also happen with Python 3 (pytest 3.2.3 with Django 1.11.4).
In my tests.py:
from __future__ import absolute_import
[...]
from .models import Demographics, Term
After changing the relative import to an absolute import the problem went away:
from taxonomy.models import Demographics, Term
HTH
Try adding the app_label = 'yourApp' in the models Meta class:
class Meta:
app_label = 'yourApp'
I got the error above. However my problem was the in the urls.py. I was following PyDanny cookiecutter django recipe. My error was to put in the urls.py this line:
url(r'^demo/', include('project.demoapp.urls', namespace='demoapp')),
when I corrected to this:
url(r'^demo/', include('demoapp.urls', namespace='demoapp')),
all was well. I also changed my local apps (I did this first and so the critical error was the url misconfiguration):
LOCAL_APPS = [
# Your stuff: custom apps go here
'demoapp.apps.DemoAppConfig',
]
I have django debug toolbar installed and this was actually causing the/my problem.
INSTALLED_APPS (in settings.py) needs the entry 'django.contrib.sessions'. Make sure to run migrate after adding.
Just add 'django.contrib.sites', to INSTALLED_APPS and set SITE_ID = 1 in your settings.py file.
Upgraded Answer for Django>=4.0 // 2022
Add Django's Sites framework and FlatPages Framework to your INSTALLED_APPS and set SITE_ID in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
'django.contrib.flatpages',
]
SITE_ID = 1
Your tests should work like a charm
This error occurred because I had created a new app folder for a subset of sites related to another feature. This needed to be added to my INSTALLED_APPS in settings.py
Django 4.1+ (2023)
After almost an hour digging, what solved for me was this:
INSTALLED_APPS = [
...
'django.contrib.sessions',
]
No need for SITE_ID or additional INSTALLED_APPS entries.
Everything worked as expected after I made a migration
python manage.py migrate
Good luck

Unable to login to django admin view with valid username and password

I know this question has been asked several times before but most of the question were asked long ago and old answers did not work for me.
I have a django-nonrel based app which is using dbindexer as backend and deployed on GAE. I am able to view homepage of my app which does not require login.
But when I try to login to admin view, it gives "wrong username / password"
On my local development server, if I use "manage.py runserver", then I am able to login on admin page. But If I run my app through GAE launcher, then I am not able to login.
I could gather that GAE launcher uses different django from "manage.py runserver".
So, how can I make GAE (on launcher as well as on deployment server) use django-nonrel?
Other details:
app.yaml does NOT include "django" library.
settings.py
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djangotoolbox',
'autoload',
'dbindexer',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'djangoappengine',
'testapp',
)
urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
UPDATE 1::
As #dragonx pointed out, I need to run
python manage.py remote createsuperuser and create the user.
On local server, when I run 'manage.py syncdb', it fills database with initializing data which also includes creating a superuser. I use 'initial_data.yaml' inside 'fixtures' directory for this and is read automatically by syncdb command.
So, Is there any way to run "syncdb' on server side? Somehow I assumed this is happening automatically at deployment just like 'manage.py runserver' happens itself and I do not need to run app manually.
If I run manage.py remote syncdb, it blurts out following error:
google.appengine.api.datastore_errors.NeedIndexError: no matching index found.
<<ed>>some stack trace<<ed>>
The suggested index for this query is:
- kind: django_content_type
properties:
- name: app_label
- name: name
Update 2:
Instead of using appcfg.py update site command, if you use python manage.py deploy from your app directory, it runs fixtures on remote server. Don't know what's doing what.
manage.py remote loaddata initdata.yaml can also be used to initialize remote database.
But even after this, I still do not see the fixtures data loaded in admin interface i.e. it seems database was not initialized or maybe admin view is badly broken. But I'd save that for another question~
When you run python manage.py runserver it starts a local dev server on your local machine. It has it's own dev datastore on your local machine. At some point you created an admin user in your local database.
When you deploy on app engine, it runs your code on Google's servers. There's a datastore there, but it doesn't share the data on your dev server. You'll need to create an admin user in the production datastore too. Try:
python manage.py remote createsuperuser

using django grappelli dashboard with dotcloud

I'm trying to set up admin with grappelli on dotcloud services. I've got that all up and running fine however when I try and add a custom dashboard to the equation, I get errors stating:
ImportError at /admin/
No module named dashboard
However I have installed the django-grappelli as required and it is working without dashboard. All the requisites for dashboard should be there.
INSTALLED_APPS = (
'grappelli.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
GRAPPELLI_INDEX_DASHBOARD = 'www.dashboard.CustomIndexDashboard'
We might need a little bit more context here. But I would first look at the following in your Django settings:
Check INSTALLED_APPS and make sure that you specify grappelli.dashboard and not just dashboard.
Check GRAPPELLI_INDEX_DASHBOARD and make sure that you specify the full path to your custom dashboard module; e.g. if the class is MyDashboard in the dashboard.py file in your myapp directory, it should be myapp.dashboard.MyDashboard.
It's a little easier to solve than I first thought.
I basically just added the files for grappelli to the project rather than depending on dotcloud to install the dependencies.
Now it works fine.