How to add authentication to a specific page in a dash application - python

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?

Related

Django, error importing view from another app

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

how can to Import from deeper subfolder?

I am trying to import my app function which is inside front/app __init__, but somehow from front.app import app it doesnt work from tooler.py.
.
├── settings
│   ├── settings.json
├── front
│   ├── app
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   └── views.cpython-36.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── demo.css
│   │   │   ├── data.json
│   │   │   └── js
│   │   │   └── script.js
│   │   ├── templates
│   │   │   └── public
│   │   │   └── index.html
│   │   ├── views.py
│   │   └── views.pyc
│   └── run.py
├── tooler.py
├── __pycache__
│   └── utils.cpython-36.pyc
├── requirements.txt
├── tester.py
├── tree
└── utils.py
run.py
from app import app
if __name__ == "__main__":
app.run()
init
from flask import Flask
app = Flask(__name__)
from app import views
I expect the output of running the server flask, but the actual output is ModuleNotFoundError: No module named 'app'

How to run django in a subpackage

My project results are as follows, django in automl/service, in automl/service/worker/suggester.py file has an import from automl.core import util and this file imported by views.py, when I run python service/manage.py runserver will raise the exception
from automl.core import util
ModuleNotFoundError: No module named 'automl'
how to solve this problem, does django can not run in a sub package?
├── automl
│   ├── __init__.py
│   ├── core
│   │   ├── __init__.py
│   │   └── base.py
│   ├── example
│   │   ├── __init__.py
│   │   └── demo.py
│   └── service
│   ├── __init__.py
│   ├── manage.py
│   ├── master
│   │   ├── __init__.py
│   │   └── urls.py
│   ├── settings.py
│   ├── worker
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── exceptions.py
│   │   ├── models.py
│   │   ├── suggester.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── urls.py
│   └── wsgi.py
├── bin
├── build.sh
├── ci.yml
├── conf
│   └── log_config.json
└── docs

How to import python function from another file into django views

I am trying to call a function from a python file that is located outside the django project directory from views.py. I have tried importing the python file but running the django server says "no module named xxxx".
Tree structure is given below.
├── auto_flash
│   ├── __init__.py
│   └── test.py
└── fireflash
├── detection_reports
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── __pycache__
│   │   └── __init__.cpython-35.pyc
│   ├── templates
│   │   └── detection_reports
│   │   └── home.html
│   ├── tests.py
│   ├── views.py
│   └── views.pyc
├── fireflash
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   └── settings.cpython-35.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── ui_cgi.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── __init__.py
└── manage.py
Project name here is "fireflash" and there is an app in that project named "detection_reports". There is another directory named "auto_flash" that has same location as "fireflash". What I want to do is to import test.py file from "auto_flash" in detection_reports.views and call a function from views. Importing like this "from auto_flash import test" throws error "no module named auto_flash".
I have tried all of the above mentioned solutions, but the cleaner solution was to append the path for auto_flash to syspath and the issue was resolved. Thanks to all of you for the efforts.
Move auto_flash to fireflash
In detection_reports add from auto_flash import test.py

PyCharm launching Django console for Flask app

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

Categories

Resources