App Configure - Module, not configured correctly? Help Divio - django

I'm using the Divio Platform to deploy a simple Django application and no matter i've done with this namespace, it's throwing an error.
I have tried adding an init.py file in the folder, as well as out of the folder and i'm quite confused to be honest as I can't think how else my application would work. I've even tried renaming the folder, adjusting in main urls but nothing seems to be working. I have already reviewed the pep420 to see if it would help, also django but I think the issue is more towards Divio as folder structure goes like this. Might I know this is the first time im using this platform.
urlpatterns = [
# Voyage application #
path('/app', include('app.urls')),
] + aldryn_addons.urls.patterns() + i18n_patterns(
# add your own i18n patterns here
*aldryn_addons.urls.i18n_patterns() # MUST be the last entry!
)
django.core.exceptions.ImproperlyConfigured: The app module <module 'app' (namespace)> has multiple filesystem locations (['/app/app', './app']); you must configure this app with an AppConfig subclass with a 'path' class attribute

Related

How to serve Django static files during development without having to run "collectstatic"?

I have a Django version 2.2.6 application that has my Django static files being served up from a separate dedicated file server. I use the Django "collectstatic" command to update the static files on my file server whenever one of them changes. I also use the django-pipeline package so that each static file contains a special string in the file name. This prevents my users' browsers from loading a static file from cache if I've updated that file. This configuration works perfectly.
I'm now in a phase in which I'm making constant changes to my CSS file to create a new look and feel to my website and it's a pain to have to remember to run the collectstatic command after each little change I make. Is there a way I can temporarily "toggle" this collectstatic configuration off while I'm doing development so that I don't have to constantly run the collectstatic command? I seem to recall there was a way to change the main urls.py file and set DEBUG = True to do something like this back in Django 1.8 but I don't see it mentioned in the latest Django documentation. What is the current "best practice" for doing this?
I think it still is in the docs.
https://docs.djangoproject.com/en/2.2/howto/static-files/#serving-static-files-during-development
In urls.py:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

django - how to disable apps

I have multiple settings_x.py
I want to disable app1 which is inside INSTALLED_APPS of one settings_1.py
I tried to comment the app, but the app is still avalaible from urls.py.
how can I do this? I dont want to delete, I just want to turn off the app.
in urls.py of project ,import settings of project.
from django.conf import settings
in urls.py of project, add this code.
if 'app1' in settings.INSTALLED_APPS:
urlpatterns += url(r'^app1/', include('app1.urls'), name='app1'),
if you add this code, system will check if the app is added to INSTALLED_APPS list in settings.py or not. If it does not exist, system will not add its urls.py configurations and also the urls of app will not work.
Apps are available even though they are not specified in settings.py. I can't imagine your case when you want to make the app unavailable from urls.py.
A solution to your problem can be using a version control system like git and using multiple branches. Delete the app in the branch where you don't need the app.

Django syncdb can't find my apps

I'm a django newbie and have been having a problem.
In my project root I created a folder called 'local_apps' and within it I put the app 'myapp'. I updated the INSTALLED_APPS within settings.py with: myproject.local_apps.myapp
However when I try to syncbd, Django gives an error: 'no module named local_apps.myapp exists'
When I put 'myapp' back in the project root, it works again but I dont want it that way. I want to keep my apps in the folder 'local_apps'.
Can you tell me what I am doing wrong here.
Thanks in advance.
I think that's a generic python error, not a Django error.
Maybe you need to create an __init__.py file in the local_apps directory, so python knows it's a module.
Do you have a models.py within the myapp folder? I think Django may need to see that file in the app.
[Edit: actually, I think wisty above may be right, make sure you have an __init__.py, if you do, try the models.py.]
I was facing the error: ImportError: No module named foo
To solve this, I just added the Django site package to the Python path at settings.py module like this:
PKG_DIR = os.path.dirname(__file__)
sys.path.append(PKG_DIR)

Setting up Django on Server with WSGI getting Import Error "Module named myproject.urls Not found"

So I have created a django site and I wanted to move it from my computer to my server. I set up Django on the server, and used the WSGI configuration. When I try to go to the home page I get an Import Error, It says that the module "myproject.urls" isn't found. It's a Django error, and it looks like it is getting the settings.py file and looking at the setting for ROOT_URLCONF and seeing the right urls file. I created this project with the usual django-admin.py startproject myproject and I just wanted to see if everything was configured correctly, but now I'm getting this error.
Any Suggestions?
Remove the "myproject" from "myproject.urls". Somehow WSGI addresses the settings as the root, so no need to refer to it again.
It sounds like myproject isn't on your path - what happens if you load up a python shell and run import myproject? If that works, what happens when you run import myproject.urls? If only the second import fails, there's a syntax error in your urls.py or one of the files it imports.
#Afrowave, you saved a huge headache - thank you from me too!
Further to this - I did a little more digging and wanted to avoid having to amend a dozen files in my app to account for loosing 'myproject.' and the start of every import.
Instead, I found if you do something like this -- you don't have to :)
ROOT = '/home/user/path_to_project_root' # In my case, also the dir that contains media, templates etc
APP_ROOT = '/home/user/path_to_django_project'
sys.path.append(ROOT)
sys.path.append(APP_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
Hope this helps someone in future.

Django + Pydev/Eclipse + Google App Engine - possible?

Has anyone been able to get Google App Engine/Django working in Pydev/Eclipse? I tried this but had difficulty getting Pydev to recognize all of the externally linked folders (django plugins) that I was referencing. I ended up copying all of those folders into the project en masse, rather than referencing them, resulting in a massively bloated project folder - it was really an unworkable solution that eventually made me give up the whole project. So, I'm wondering if anyone has tried this or has any idea what I might have been doing wrong. (Keep in mind this was my first attempt at using Pydev, Django, App Engine and Python!!)
I haven't personally set it up but i did see this tutorial on how to do it:
http://code.google.com/appengine/articles/eclipse.html
Pydev 1.4.6 (still only available in the nightly builds) has some special support to easy in the configuration. See: http://pydev.blogspot.com/2009/05/testing-on-pydev-146-google-app-engine.html
This tutorial shows how to configure Aptana (with PyDev installed) to be your coding and debugging platform for AppEngine. Similarly you can add Django libraries to Aptana too.
http://www.alishabdar.com/2009/05/06/develop-google-appengine-with-aptana-studio/
This question hasn't been replied to for some time and things have changed, so I thought I would provide and update.
PyDev now includes a Google App Engine configuration out of the box and you can debug and run GAE projects out of the box, this includes Django.
Just install GAE and the latest Eclipse/PyDev on your machine then create a GAE project and point PyDev at your versions of Python and Google App Engine.
appengine 1.31
Django 1.1
pydev 1.5.4
OS Ubuntu 9.10
eclipse .pydevproject file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
<key>GOOGLE_APP_ENGINE</key>
<value>/home/elvis/google_appengine</value>
</pydev_variables_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pythonleggo</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>${GOOGLE_APP_ENGINE}</path>
<path>${GOOGLE_APP_ENGINE}/lib/webob</path>
<path>${GOOGLE_APP_ENGINE}/lib/yaml/lib</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
Files:
eclipse project folder
- app.yaml
- index.yaml
- init.py
- main.py
- manage.py
- .project
- .pydevproject
- settings.py (unable to load)
- urls.py
main.py:
from google.appengine.dist import use_library
use_library('django', '1.1')
from django.conf import settings
settings.configure(
DEBUG=True,
TEMPLATE_DEBUG=True,
ROOT_URLCONF = 'urls',
PROJECT_NAME = 'pythonleggo',
SETTINGS_MODULE = '.settings',
ADMINS = ('elvis', 'elvis#gmail.com'),
LANGUAGE_CODE = 'en-us',
SITE_ID = 1,
USE_I18N = True,
MEDIA_ROOT = '',
MEDIA_URL = '',
ADMIN_MEDIA_PREFIX = '/media/',
SECRET_KEY = 'shhh',
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source'),
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware'),
TEMPLATE_DIRS=('/home/jmurphy/workspace/pythonleggo/templates'),
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites')
)
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
from google.appengine.ext.webapp import util
def main():
# Run Django via WSGI.
application = django.core.handlers.wsgi.WSGIHandler()
util.run_wsgi_app(application)
if __name__ == ' __main__':
main()
eclipse run:
/usr/bin/python2.6 -u /home/elvis/google_appengine/dev_appserver.py
The PYTHONPATH that will be used is:
/home/elvis/.eclipse/org.eclipse.platform_3.5.0_155965261/plugins/org.python.pydev_1.5.4.2010011921/PySrc/pydev_sitecustomize:/home/elvis/workspace/pythonleggo:/home/elvis/google_appengine:/home/elvis/google_appengine/lib/webob:/home/elvis/google_appengine/lib/yaml/lib:/usr/lib/pymodules/python2.6:/usr/lib/pymodules/python2.6/gtk-2.0:/usr/lib/python2.6:/usr/lib/python2.6/dist-packages:/usr/lib/python2.6/dist-packages/PIL:/usr/lib/python2.6/dist-packages/gst-0.10:/usr/lib/python2.6/dist-packages/gtk-2.0:/usr/lib/python2.6/lib-dynload:/usr/lib/python2.6/lib-old:/usr/lib/python2.6/lib-tk:/usr/lib/python2.6/plat-linux2:/usr/local/lib/python2.6/dist-packages
I could not get the settings file to load using os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' . It appeared to be stripped from the environ that django received. I used settings.configure which appeared to work correctly. At this point I only have the default django page loading in appspot.
I originally linked to this tutorial. Pydev now has Django support so this is probably less relevant. It may still be useful for figuring out how to make them all work together though. You could also try looking at this blog post.
I've just started with Python and the Google App Engine today. I think we both banged our heads against the same wall with external referencing.
I've tried deploying the google-app-engine-django project for my app. I've extracted everything and I have under my root the /appengine_django and /django folder.
I've added them as source folders, and I've added the /google_appengine/google folder as an external reference.
Normally, this all made sense to me. Each contained the __ init __.py module. Still, when I tried to ctr+click on any of the import statements it couldn't resolve the path to the modules.
Strikingly, you do not import the immediate folder that contains an __ init __.py. To properly reference packages you import the parent folder that contains the package duh! That also means that, since I didn't want to use a /src folder, the actual project folder should be added as a source reference to get the /appengine_django and /django to be recognized as source folders.
With that done, everything is running smoothly. I guess it's to show I have more reading up to do on Py.
Here is an other tutorial that might help.
The eclispe version might be a bit old but it should get you
far enough to get a working project.
http://django-appengine.com/contents
It has complete eclipse set up
http://django-appengine.com/post/37462709481/
http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/
It has complete gae set up
http://django-appengine.com/post/37615321945/
It has complete django set up
http://django-appengine.com/post/37628665099/
And then explains how to combine those two projects
into one gae project.
http://django-appengine.com/post/37778427717/
I hope this helps others who are just starting out