How to run django local host and activate virtual env by using single command? - django

I M New to Django, Whenever I open my project, everyday i type CMD to activate virtual env then, to open local server i use runserver, but I want to open my local host by using single command. Is there any way to do that?

If you want to run command using shell script you have to open text editor and write your desired command. then save it as .bat file. It will create a executable file and simply use double click to run it. if you have multiple command use '&' between them.
Example
cd your directory &
python manage.py runserver

Related

Startup script NOT running in instance

I have a instance where I have some Flask web app. In order the app to start when the VM is booted I have included a startup script:
#!/bin/sh
cd documentai_webapp
cd docai_webapp_instance_gcp
sudo python3 server.py
However, this is not at all executed, anyone can help me?thanks!
PD: When I execute this script manually within the VM it works perfectly fine
As context it is necessary contemplate:
For Linux startup scripts, you can use bash or non-bash file. To use a non-bash file, designate the interpreter by adding a #! to the top of the file. For example, to use a Python 3 startup script, add #! /usr/bin/python3 to the top of the file.
If you specify a startup script by using one of the procedures in this document, Compute Engine does the following:
Copies the startup script to the VM
Sets run permissions on the startup script
Runs the startup script as the root user when the VM boots (missing step from #Andoni)
For information about the various tasks related to startup scripts and when to perform each one, see the Overview.

"Permission denied" on file when running a docker container

I have a file that I can't edit but needs to run on in a docker container. Because the file doesn't have an extension, I have to use chmod for setting the file executable. But after I build the docker image from the docker file I always get a "permission denied" error
My docker file:
FROM alpine
COPY . /home/guestuser/bin/gateway
RUN apk add libressl-dev
RUN apk add libffi-dev
RUN pwd
WORKDIR /home/guestuser/bin/.
RUN ["chmod", "+x", "gateway"]
RUN pwd
CMD ["/home/guestuser/bin/gateway"]
EXPOSE 11878
I alwas get this error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/home/guestuser/bin/gateway\": permission denied": unknown.
As I already mentioned, I am not able to edit the file I want to execute. What am I doing wrong?
You may try this simple one.
FROM alpine
COPY . /home/guestuser/bin/gateway
RUN apk add libressl-dev
RUN apk add libffi-dev
WORKDIR /home/guestuser/bin/
RUN chmod -R 755 /home/guestuser
CMD ["/bin/bash", "/home/guestuser/bin/gateway"]
Otherwise, run sleep command login to container and see your commands works manually
It looks like you are using the exec form of CMD, as shown here
There are two ways to use CMD. The first is the way you are already doing it, in exec form:
CMD ["/home/guestuser/bin/gateway"]
Or you could use shell form:
CMD /home/guestuser/bin/gateway
If you need a shell you could also explicitly call one in exec form, which is what Ganesh was trying to suggest.
CMD ["sh", "/home/guestuser/bin/gateway"]
But if that syntax is correct, why didn't it work?
Well, because this is assuming that gateway is a file. The issue is... it probably isn't.
When you run this command:
COPY . /home/guestuser/bin/gateway
From the reference:
Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build.
You are copying the entire contents of the build context into the directory /home/guestuser/bin/gateway. If you want to copy a specific file, you should name it explicitly rather than using . The COPY command's syntax is source first, then destination, as shown here.
So when you are trying to execute gateway, you are probably "executing" a directory named gateway. So long as there is more than one file in the build context, gateway will be a directory. That can include the Dockerfile itself, so even if the build context is a folder with just the Dockerfile and the script you want to run, you'll still pull in both files, which turns gateway itself into a directory.
Tests you can try
As proof that your Dockerfile CMD syntax is correct, try changing that CMD to something like this:
CMD ["top"]
Similarly, you can remove the CMD and just run the container in interactive mode. It will drop you in your WORKDIR, which is empty except for the gateway directory, complete with the contents of whatever directory structure was pulled in during the build process.
So, to make this work, change your COPY line to name the script you want:
COPY somescript /home/guestuser/bin/gateway
Other notes:
your default user here is root, so you don't need to chmod gateway
RUN pwd will only show the first time you build the container

How to re-enter my virtual environment using cmd in windows

I have created a virtual environment for django using cmd
pip install virtualenvwrapper-win
mkvirtualenv test
and here I have installed Django using
pip install django
But suppose I close my cmd prompt and restart it. What is the command to re-enter in the (test) environment that I have created.
If you are using the package virtualenvwrapper-win, then you can use the options described in this part of the docs:
workon [<name>]
If <name> is specified, activate the environment named <name> (change the working virtualenv to <name>). If a project directory has
been defined, we will change into it. If no argument is specified,
list the available environments. One can pass additional option -c
after virtualenv name to cd to virtualenv directory if no projectdir
is set.
To reactivate the virtual environment:
Virtualenvname\Scripts\activate.bat
Eg:testing\Scripts\activate.bat
This will opens your virtual environment to use.
To create a virtual environment open command prompt/terminal and navigate to the directory where you want to create your Django project. Let’s say we want to create our project at 'user/hp/' then we’ll navigate to the 'user/hp/' and then type the command below.
Install the virtual environment
Create a virtual environment
C:\Users\hp\mkvirtualenv jangoProject
To activate env type the below command.
C:\Users\hp\jangoProject\Scripts\activate
To deactivate env type the below command
To create a new project type below code
C:\User\hp\django-admin startproject learn1
to re entering the same virtual environment created earlier one should firstly change to the directory where virtual environment is created using the CD(directory).
and later change in to the project directory and then change to SCRIPTS
and at that moment use the command ACTIVATE to activate the virtual environment.
steps:
cd #project name
cd scripts
cd ..
use command #activate
follow the above steps to reactivate virtual environment.
To activate previously created environment, just type the following command in your anaconda prompt:
conda activate 'name_of_the_environment'
Voila! You are now on your virtual environment.

Informatica powercenter shell not working

I tried to run command task to changes clear contents of a file using .sh commands and printf, but neither one isn't working. where as I'm able to run mkdir,copy and rm are working.
Just wondering should I have to change any configuration settings for clearing and write contents of a file.

Batch command within .py Pyinstaller causing error

I'm creating a standalone/portable exe via pyinstaller that can be run from a PC without python. The problem I'm having is the batch command I'm using within the .py file to start SimpleHTTPServer and serve to a specific directory. This code (batch command):
os.chdir('c:\MC\log')
os.system('cmd /c start python -m SimpleHTTPServer 8080')
It errors because of the direct reference to "python" in the command. My question is how can I include this batch command without referencing python OR is there another method to start SimpleHTTPServer and serve to a specific directory?