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.
Related
The apps i create are working with out any need for them to be registered in settings.py of the project.
The official documentation also doesn't register its polls app in INSTALLED_APPS. https://docs.djangoproject.com/en/3.0/intro/tutorial01/
What is the use of registering apps in INSTALLED_APPS of settings.py if it works with out registering?
In python, anything you import is known to the code where it is imported, but the inverse is not possible...
Imagine I have two files
# a.py
def foo():
...
# b.py
from a import foo
def bar():
foo()
In b.py I know about foo, but a.py doesn't know about bar or even that b.py exists.
Now when you have a router, you import your views which import models, etc. Your full app can work with this. But for Django to know about your app it needs at least some reference to it. The INSTALLED_APPS in settings tells Django which apps are meant to be part of your entire Django project. By default, it includes some Django apps. Not every project needs all of them so some (or all) might be removed. Similarly, other 3rd party apps might be added.
Running Django management commands such as migrate or collectstatic will only work on apps included in INSTALLED_APPS.
P.S: Never access INSTALLED_APPS in your code, but rather use the app registry via from django.apps import apps
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
I'm in a selection process and I must develop a software in Django with the restriction of not being able to use the admin included in the framework.
I tried removing it from the INSTALLED_APPS. But when I run a migration I get the error:
'No installed app with label 'admin'
Is there any other configuration that I should do or what is the correct way to do it?
Be sure to remove it from:
urls.py
remove from urlpatterns
remove the import statement
INSTALLED_APPS
That's it.
In my django project named website I have two apps app1 & app2 . I want to keep app2 accessible only through my local machine. I dont want app2 to be publicly accessible online through my website. I have already pushed my entire website to heroku. So how can I delete app2 from heroku website and avoid pushing app2 to heroku in future.
I have tried following things:
Added app2/ to .gitignore. So future changes are avoided. But current version of app2 still exist on heroku website.
I deleted app2 on local machine and tried to push the changes, but I got error in static collection saying no app named app2 exists.
I would also like to avoid having Django's default admin functionality available through my website. I would like to keep it local too.
Thanks
I would keep both apps under version control, then control the differences through settings. For example, if you only have DEBUG set locally:
settings.py
if settings.DEBUG:
INSTALLED_APPS += ['app2']
urls.py
from django.conf import settings
if settings.DEBUG:
urlpatterns = [
include('app2/', include('app2.urls')),
] + urlpatterns
This is just an example, without knowing more about your project, it is hard to show exactly how to do it. But with this example, app2 would only be loaded and have routes available when the DEBUG setting was True.
I want to be able to import things from applications in my project without referring to my project name.
My folder structure is like so; I have a project called djangoproject1, and inside I have a folder called apps, and then I have my individual apps in that folder.
djangoproject1, apps, and all my applications have an empty "__init__.py" file in them.
In my settings.py file I have the following code:
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))
I've tried adding my apps to INSTALLED_APPS several ways:
'djangoproject1.apps.app1',
'djangoproject1.apps.app2',
or
'apps.app1',
'apps.app2',
or
'app1',
'app2',
but nothing works. Whenever I try to do:
from app1 import *
I got an unresolved import error. I'm using the latest versions of eclipse and django
Ok, so I got it to work by adding the apps folder to the PYTHONPATH through eclipse under Project Properties. Is this eclipse only though? I'm not sure how this will work when I try and deploy the site. What do you guys think?
The statement sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps")) looks OK to me. Following this you only need to add app1 to INSTALLED_APPS and everything should work. But apparently they are not working.
Try the following: 1. Print your sys.path and verify that your project's app directory is in the list. 2. Double check that your have an __init__.py inside your apps folder.
Update
OK. Now can you fire up Django shell and try importing again? If it fails, please post the stack trace here.
You must include apps directory to PYTHONPATH. Be sure that in apps directory don't have __init__.py, because it become a package instead of "simple directory". Than, include in settings.py
app1, app2, app3
Use
from app1 import *