Given this blog project which has posts and comments apps:
blog
├── blog
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── comments
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
└── posts
├── __init__.py
├── admin.py
├── apps.py
├── migrations
│ └── __init__.py
├── models.py
├── tests.py
└── views.py
I want to be able to run each of the apps (services) independently. The django-admin runserver runs the whole app which is not what my intention. I want to run and deploy services independently, each with its own db and port, and choose which services to start in advance. I'm aware that each app can have its own db specified in settings.py. Not sure about how to run services independently though. I also want the resulting project structure to be PyCharm-friendly, which means I can choose which services to run within the same project workspace.
Related
I would like to know how Django's imports work. For example, in this code:
# in some_app/views.py
from another_app.models import UserModel
# another_app is another app of the same project
there's an import statement that imports UserModel from models.py in another_app (another app of the same project).
I was just wondering how Django handles this importing because usual Django project's directory structure looks like this:
.
├── another_app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── manage.py
├── some_app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
└── some_project
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
some_app and another_app are separate directories.
I want to know how the importing works because I want to find a workaround for one of my projects that have separate directories but requires each other's functions.
If you register the app name in installed app in django settings you can easily handle most migrations and other stuff other wise you can just branch off from the folder of the app name.
What i recommend is making a separate directory named app and you can place all your app inside app director so the app and project directory gets separated easily and your import will also be easy
you can import in this manner after wards
from app.some_new_app_name.models import MyModel
from app.some_new_app_name_2.models import MyModel2
I have a dash app with multiple pages.
.
├── adduser.py
├── app.py
├── apps/
│ ├── __init__.py
│ ├── exome.py
│ ├── familial.py
│ ├── oncomine.py
│ ├── prenatal.py
│ ├── rapidexome.py
│ └── targeted.py
├── auth.py
├── data/
├── dataprocessor.py
├── index.py
├── layouts.py
└── static
└── fileiconn.png
I just want to prompt the use for an admin password when they try to access the /apps/exome route. is there a way to do that?
I'm trying to import a view from one app to another in my project.
When using this:
from ..from ..KnownLocation.views import KnownLocationView
I get the following error:
ValueError: attempted relative import beyond top-level package
When trying to use:
from triangulationapi.KnownLocation.views import KnownLocationView
It's raising the following error.
ModuleNotFoundError: No module named 'triangulationapi.KnownLocation'
my Project tree:
├── find_second_gdt
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── __pycache__
│ ├── second_GDT_finding
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── __init__.py
├── KnownLocation
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ ├── models.py
│ ├── __pycache__
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── manage.py
├── requirements.txt.
└── triangulationapi
├── asgi.py
├── __init__.py
├── __pycache__
├── settings.py
├── urls.py
└── wsgi.py
And, what's the diffrence between using .. and project.app.view...
I thought it is the same up until now.
Try this:
from .KnownLocation.views import KnownLocationView
I have setup celery in my django project using official documentation at
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-django
So my project structure is
└── mysite
├── db.sqlite3
├── manage.py
├── mysite
│ ├── celery.py
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── polls
├── admin.py
├── apps.py
├── forms.py
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── tasks.py
├── tests.py
└── views.py
polls is application
polls/tasks.py have class based celery task.
Currently tasks.py have many tasks so that file is too big. I want to keep each task in separate file like
mysite/polls/
├── admin.py
├── apps.py
├── forms.py
├── __init__.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── tasks # I want to keep easy task in separate file like this
│ ├── __init__.py
│ ├── download_task.py
│ ├── process_task.py
│ └── upload_task.py
├── tests.py
└── views.py
How to make this setup working?
That is 100% correct. In your tasks/__init__.py file, make sure to import the tasks from the other files:
from .download_task import *
from .process_task import *
# etc...
And then make sure you have the autodiscover_tasks call in your celery.py file to discover the tasks in each of your INSTALLED_APPS.
For whatever reason, PyCharm thinks my Flask project is a Django project, and thus launches a Django console instead of a Python console in the toolbar:
The project interpreter is configured properly:
Here is my project hierarchy, if it's relevant:
.
├── LICENSE
├── README.md
├── app
│ ├── __init__.py
│ ├── email.py
│ ├── main
│ │ ├── __init__.py
│ │ ├── errors.py
│ │ ├── forms.py
│ │ └── views.py
│ ├── models.py
│ ├── static
│ │ └── favicon.ico
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── base.html
│ ├── index.html
│ └── mail
│ ├── new_user.html
│ └── new_user.txt
├── config.py
├── data-dev.sqlite
├── data-test.sqlite
├── manage.py
├── migrations
│ ├── README
│ ├── alembic.ini
│ ├── env.py
│ ├── script.py.mako
│ └── versions
│ ├── 38c4e85512a9_initial_migration.py
├── requirements.txt
└── tests
├── __init__.py
└── test_basics.py
Just because there is a module called manage.py doesn't mean I'm working on a Django project!
How can I fix this?
You can disable Django support for your project here:
Settings > Language & Frameworks > Django