setting up django for deployment - python-3.x

I'm trying to deploy my Django app I've split the settings.py and put in a settings folder. Now before I run my server, I must first this
set DJANGO_SETTINGS_MODULE=src.settings.dev
How can I make the above command to be automatic so I don't have type it every time before running the server .thanks

edit the below line in your manage.py for example in my case was
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'src.settings.dev')

Related

Google Cloud Run Second Flask Application - requirements.txt issue

I have a google cloud run flask application named "HelloWorld1" already up and running however i need to create a second flask application. I followed the below steps as per documentation:
1- On "Cloud Shell Editor" clicked "<>Cloud Code" --> "New Application" --> "Cloud Run Application Basic Cloud Run Application .."-->"Python (Flask): Cloud Run", provide and new folder and application is created.
2- When i try to run it using "Run on Cloud Run Emulator" i get the following error:
Starting to run the app using configuration 'Cloud Run: Run/Debug Locally' from .vscode/launch.json...
To view more detailed logs, go to Output channel : "Cloud Run: Run/Debug Locally - Detailed"
Dependency check started
Dependency check succeeded
Starting minikube, this may take a while...................................
minikube successfully started
The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration /home/mian/newapp/.vscode/launch.json
Update initiated
Update failed with error code DEVINIT_REGISTER_BUILD_DEPS
listing files: file pattern [requirements.txt] must match at least one file
Skaffold exited with code 1.
Cleaning up...
Finished clean up.
I tried following:
1- tried to create different type of application e.g django instead of flask however always getting the same error
2- tried to give full path of [requirements.txt] in docker settings, no luck.
Please if someone help me understanding why i am not able to run a second cloud run Flask app due to this error?
It's likely that your Dockerfile references the 'requirements.txt' file, but that file is not in your local directory. So, it gives the error that it's missing:
listing files: file pattern [requirements.txt] must match at least one file

Build variables not accessible in my react native app

I need to inject env variables into my code.
I'm using azure pipelines to build my android app in react native.
I have set env variables in the build configuration and I have created a file called appcenter-post-clone.sh. The contents of this file are as follows:
ENV ADMIN_HOST= $ADMIN_HOST
And in my build configuration I have defined
ADMIN_HOST = https://example.com.
But I'm getting this error, [command]/bin/bash /Users/runner/runners/2.160.1/work/1/s/appcenter-post-clone.sh
ENV: https://example.com: No such file or directory. What I fail to understand here is, why is azure treating the value of my env variables as a file? How do I make this work?
The blunder I made here is, I should have used
ENV ADMIN_HOST=$ADMIN_HOST
Without the space. That solved it for me.

How to host Python 3.7 flask application on Windows Server?

As wfastcgi module is not compatible with Python 3.7, What is the best way to host a python flask application on a Windows Server?
you need to install the python,wfastcgi, and flask at your server.
You can download the python from below link:
https://www.python.org/downloads/
after installing python download the wfastcgi:
pip install wfastcgi
run the command prompt as administrator and run this command.
wfastcgi-enable
run this command to enable wfastcgi.
below is my flask example:
app.py:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
after creating an application to run it use below command:
python app.py
now enable the cgi feature of iis:
now open iis.
right-click on the server name and select add site.
enter the site name physical path and the site binding.
after adding site select the site name and select the handler mapping feature from the middle pane.
Click “Add Module Mapping”
add below value:
executable path value:
C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py
Click “Request Restrictions”. Make sure “Invoke handler only if
request is mapped to:” checkbox is unchecked:
Click “Yes” here:
now go back and again select the server name and select fast CGI setting from the middle pane.
Double click it, then click the “…” for the Environment Variables
collection to launch the EnvironmentVariables Collection Editor:
Set the PYTHONPATH variable:
And the WSGI_HANDLER (my Flask app is named app.py so the value is
app.app — if yours is named site.py it would be site.app or similar):
Click OK and browse to your site:
Note: Do not forget to assign the iusr and iis_iusrs user permission to the flask site folder and python folder.

NodeJS Google Vision is unable to detect a Project Id in the current environment

Under Ubuntu environment, NodeJS Google Vision complains:
Error: Unable to detect a Project Id in the current environment.
Even though I already put json credential through
$ export GOOGLE_APPLICATION_CREDENTIALS=/var/credential_google.json"
Please help.
As a quick hack you can try this :
$ GOOGLE_APPLICATION_CREDENTIALS="/var/credential_google.json" node app.js
It's not recommended to use a .json config file locally. I've seen these leak on production servers causing whole platforms to be deleted + the introduce environmental switching and security issues.
Setup Google Cloud CLI.
Now the server will 'look' at the local environment and use that.
If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id.
You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running.
Run
gcloud config set project [some-project-id]
Now if you run (node example)
"dev": "NODE_ENV=dev GCP_PROJECT=some-project-id nodemon index.ts",
It will load the project environment. This also allows you to deploy easier with:
"deploy:dev": "y | gcloud app deploy --project some-dev-project app.yaml",
"deploy:prod": "y | gcloud app deploy --project some-prod-project app.yaml"
App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.
If you are usually a windows user and trying out Ubuntu (like me), the problem is likely with the assumptions that the export command exports variable to all terminal sessions and that you need to open a new terminal to get it to use (as expected in a windows terminal for an environment variable).
The export command doesn't export the variable to another terminal session. So if you export it in a terminal, you use it on the same terminal.
If you would like to export it permanently, then you can try the solution listed here
You can put the path to the JSON credentials directly when instantiating the client, by passing it as an argument.
For example:
const client = new speech.SpeechClient( {keyFilename: "credential_google.json"});
Also, for me setting it in the terminal didn't work.

Kibana 4 configuration for production

I'm trying to deploy Kibana 4 to Azure Websites. I can't use bin/kibanta.bat file since Azure Websites uses start script in package.json to bootstrap application. I tried to update package.json start script to run bin\kibana.js file and environment variables in it. After that Azure starts running Kibana server but I'm getting this error: Uncaught ReferenceError: ZeroClipboard is not defined (http://kibana-site.azurewebsites.net/index.js?_b=5827:89458). Does anyone tried to make Kibana 4 run not using bin\kibana* files? Maybe I have to specify additional environment variables?
The solution is explained here: https://github.com/elastic/kibana/issues/2617
It's a bug that was fixed later.

Resources