Trying to create a super user for my database:
manage.py createsuperuser
Getting a sad recursive message:
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually.
Seriously Django? Seriously?
The only information I found for this was the one listed above but it didn't work:
Unable to create superuser in django due to not working in TTY
And this other one here, which is basically the same:
Can't Create Super User Django
If you run $ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run manage.py createsuperuser in your project to create one manually. from Git Bash and face the above error message try to append winpty i.e. for example:
$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):
To be able to run python commands as usual on windows as well what I normally do is appending an alias line to the ~/.profile file i.e.
MINGW64 ~$ cat ~/.profile
alias python='winpty python'
After doing so, either source the ~/.profile file or simply restart the terminal and the initial command python manage.py createsuperuser should work as expected!
I had same problem when trying to create superuser in the docker container with command:
sudo docker exec -i <container_name> sh. Adding option -t solved the problem:
sudo docker exec -it <container_name> sh
In virtualenv, for creating super-user for Django project related to git-bash use the command:
winpty python manage.py createsuperuser.
Since Django 3.0 you can create a superuser without TTY in two ways
Way 1: Pass values and secrets as ENV in the command line
DJANGO_SUPERUSER_USERNAME=admin2 DJANGO_SUPERUSER_PASSWORD=psw \
python manage.py createsuperuser --email=admin#admin.com --noinput
Way 2: set DJANGO_SUPERUSER_PASSWORD as the environment variable
# .admin.env
DJANGO_SUPERUSER_PASSWORD=psw
# bash
source '.admin.env' && python manage.py createsuperuser --username=admin --email=admin#admin.com --noinput
The output should say: Superuser created successfully.
To create an admin username and password, you must first use the command:
python manage.py migrate
Then after use the command:
python manage.py createsuperuser
Once these steps are complete, the program will ask you to enter:
username
email
password
With the password, it will not show as you are typing so it will appear as though you are not typing, but ignore it as it will ask you to renter the password.
When you complete these steps, use the command:
python manage.py runserver
In the browser add "/admin", which will take you to the admin site, and then type in your new username and password.
Check your docker-compose.yml file and make sure your django application is labeled by web under services.
I tried creating superuser from Stash [ App: Pythonista on iOS ]
[ Make sure migrations are already made ]
$ django-admin createsuperuser
I figured out how to do so. What I did was I went to VIEWS.py. Next, I imported the module os. Then I created a function called createSuperUser(request):. Then, I then created a variable called admin and set it equal to os.system("python manage.py createsuperuser"). Then after that, return admin. Finally, I restarted the Django site, then it will prompt you in the terminal.
import os
def createSuperUser(request):
admin = os.system("python manage.py createsuperuser")
return
Related
I downloaded a folder with multiple python files in the form of a Django project for a course and I am unable to run it. Usually, when you create a Django project it is created within the terminal with the line django-admin startproject web_project . and then python manage.py migrate is used and then the line python manage.py runserver to start a server.
How do I start a server to run my project?
When I use django-admin startproject web_project ., it creates a new project which I don't want. When I use python manage.py migrate or python manage.py runserver it says:
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3
But even when I used python3 manage.py migrate or python3 manage.py runserver instead and it returned:
python3: can't open file 'manage.py': [Errno 2] No such file or directory
At first make sure you opened command prompt or terminal in right directory(in projects directory) when you are running the runserver command.
If you are on windows open the project folder(the folder that contains files like manage.py), then right click and press open PowerShell window here.
first of all I recommend creating a virtual environment using the following command
python3 -m venv .env
then activate it
source .env/bin/activate
"django-admin statproject" its for initalite a new project for running an excited Django app you should just install Django - if there is now "requirements.txt" file- , migrate and run.
pip install Django
python manage.py migrate
python manage.py runserver
I'm doing the CS50Web course, and there is a Django project in which I want to create a new app called "wikipedia". The problem is that after I run this command in Windows PowerShell:
python manage.py runserver
this loop happens:
loop print
I don't know what I did wrong for that to happen. After running
python manage.py startapp wikipedia
, I:
went to my Django project and added 'wikipedia' in the installed apps in settings.py
went to urls.py and added a path like this:
path("wiki/", include("wikipedia.urls))
And then I tried running the server. What did I do wrong?
You must have something improperly configured.
Run this:
$ pip uninstall django
$ pip install django
$ django-admin startproject <projectname>
$ cd <projectname>
$ django-admin startapp wikipedia
$ python manage.py makemigrations
$ python manage.py migrate
do what you described in your question
Also, it is always a better idea to run these things in the CMD, rather than in the PowerShell
Are you sure you have url mappings in your wikipedia app urls.py? Not having any patterns there could be the cause of an error.
I have a problem in setting up django.
My situation: I have Anaconda Python 2.7 in my Windows 8 computer. On the Anaconda command prompt window, I type: pip install django. This is successful.
Then I create a folder named "newproject". On the command prompt I went to the folder "newproject". Then django-admin.py startproject newproject. This is successful.
Then I run python manage.py runserver. It tells me
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I checked out udemy django installation guide and other guides on the net. I have even set up a virtual environment. But the main problem is always: can't open file 'manage.py'
You're not in the proper directory...In the case you described, you should have:
mkdir newproject (not sure why you're doing this...but we'll continue with it)
cd newproject
django-admin.py startproject newproject
cd newproject ← A key missing part from what you did. You need to change into the directory where manage.py resides. Verify it by using ls at the command prompt after switching into the directory.
python manage.py runserver
Use ls often, if you need, to double check where you are in the directory tree.
You are not in the correct directory. You need to do cd newproject and the execute your runserver command.
For me it was because the manage.py didn't get created and the problem was that:
In windows instead of typing "django-admin.py" just type "django-admin" and it will create the manage.py file
you need to change your directory to the directory of the project.
open your environment by typing activate environment_name
change the directory to the folder in which you want to create the
project by cd Folder_Name
then create your project by django-admin startproject
Project_Name
then change the directory to your project folder
if you also want to create an app then typepython manage.py
startapp App_name
to confirm if it works type python manage.py runserver, then
you should get a link in the terminal. copy and paste that link in
the browser and you should see a successful page.
The reason of this problem is because you're in the first project directory "parent directory", and you have to go to your project "newproject" that has the manage.py file.
The way to this is simple:
cd "name of your project", E.g. cd newproject
python manage.py runserver
You need to include a . after you create the project.
Eg: django-admin.py startproject newproject .
This will allow you to run python manage.py runserver from where you are.
That can happen because manage.py doesn't have permissions.
Check the existence of manage.py throughout newproject, If exist you can fix it with:
$cd newproject
$chmod +x manage.py
Finally, try to execute python manage.py runserver
I was having the same problem, when Windows 10 changed credentials, Docker lost the access to drives. The fix for this issue, I reset the credentials in docker-desktop > shared Drives > reset credentials at bottom.
can't open file 'manage.py': [Errno 2] No such file or directory"
here is the solution
step 1: command -> django-admin startproject project_name
step 2: command -> cd project_name
step 3: command -> python manage.py startapp app_name
try it may fix your problem
You should navigate to the inner directory where your manage.py resides. For example:
If you have created projectname as
Django-admin startproject loginapp
Step 1: Go to loginapp
Step 2: Click on it
Step 3: You will find another loginapp and manage.py folder inside that
Step 4: Use this rootpath commandprompt
Step 5: Enter py manage.py runserver
Now it will work
I ran into the same error seller. But this is what I discovered
1: open your terminal in your project environment
2: install Django using: pip install django (if you are on windows)
3: then create your Django project using : django-admin startproject newproject . (django-admin start-project followed by project name give a space and add period (.) )
So it goes like this
django-admin startproject new project .
The period/fullstop (.) At the end tells djando the area in which the file should be created which is inside the project file its self you are working on. After this is done you are free to go. You can now run your server and enjoy
Run server using: python manage.py runserver
Make sure to put a period at the end of your command e.g
Django-admin startproject new project .
The period at the end (.) will solve the problem
There could be invalid interpreter selected .Try selecting the proper interpreter
I go through first django tutorial from djangoproject.com and at the very beginning of part 2, which is creating superuser when I run "python manage.py createsuperuser" I get the following message back:
Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.
I get the same message when I go on to create superuser after running syncdb.
I am working on Eclipse for Windows 7, and Django 1.7.1 together with Python 2.7.8.
When using the Git Bash and to correct the above error message try to append winpty i.e. for example:
$ winpty python manage.py createsuperuser
Username (leave blank to use '...'):
You can create a superuser using django shell (python manage.py shell)
from django.contrib.auth.models import User
User.objects.create_superuser(username='YourUsername', password='hunter2', email='your#email.com')
if you are in virtualenv, cd into your virtualenv and activate it. then try these steps:
python manage.py syncdb --noinput
python manage.py migrate
python manage.py createsuperuser
Use "Windows PowerShell" or "Windows Cmd" and then use same command. Git command interface has some restriction.
I am a Windows10 user. I tried to run py manage.py createsuperuser command using Git Bash console, but error has been thrown. Then I switched Git Bash to native Windows Command Line with administrator privileges, and re-run command - it was working.
First run
$ django-admin startproject mysite
in cmd prompt,then apply migration by
cd mysite
mysite:
python manage.py makemigrations
then
python manage.py migrate
after that
python manage.py createsuperuser
From Django 3.0 you can do it without TTY
DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=psw \
python manage.py createsuperuser --email=admin#admin.com --noinput
also, you can set DJANGO_SUPERUSER_PASSWORD as the environment variable
If you are Windows user using GitBash terminal and trying to create super for admin it won't work instead of that use command prompt in administrative privilege it works
Gitbash terminal error
$ python manage.py createsuperuser
Superuser creation skipped due to not running in a TTY. You can run "manage.py createsuperuser" in your project to create one manually.
Error Resolved Using Command Prompt
python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address:
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
This might be helpful for others. Do Upvote for this if it works for you
Use this command :
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py createsuperuser
python manage.py runserver
Your error is probably:
[Error `You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, content types, sessions.
Run 'python manage.py migrate' to apply them.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)`][1]
check you yo directory with Tree command:tree
Then run Make migration :
enter image description here
then create superuser with the python3 manage.py createsuperusercommand :
Is there any way by which I can run syncdb from my terminal? I don't know why my action_hooks/deploy script is not running. When I open my openshift database it show no table created.
source ${OPENSHIFT_HOMEDIR}python-2.6/virtenv/bin/activate
export PYTHON_EGG_CACHE=${OPENSHIFT_HOME_DIR}python-2.6/virtenv/lib/python-2.6/site-packages
echo "Executing 'python ${OPENSHIFT_REPO_DIRwsgi/my/manage.py syncdb --noinput'"
python "$OPENSHIFT_REPO_DIR"my/manage.py syncdb --noinput
echo "Executing 'python ${OPENSHIFT_REPO_DIR}wsgi/my/manage.py collectstatic --noinput -v0'"
python "$OPENSHIFT_REPO_DIR"my/manage.py collectstatic --noinput -v0
git repo at https://github.com/sarvesh-onlyme/ninja/tree/master/openshift/django
How about:
source $OPENSHIFT_HOMEDIR/python-2.6/virtenv/bin/activate
cd $OPENSHIFT_REPO_DIR/wsgi/$OPENSHIFT_APP_NAME
python manage.py syncdb --noinput
Please make sure to do something similar if your application type is python 2.7 based.
let me know if it does not work.
check logs (rhc tail app_name). Try to login to OpenShift app through ssh (rhc ssh app_name) and try to run deploy script manually (cd app-root/runtime/repo/.openshift/action_hooks; ./deploy). Do you see any errors?
Post your logs/errors here. I will update my answer afterwards.
//lol, sorry, I did not notice it's two year old question.