789๐
A more simple solution just type sudo fuser -k 8000/tcp
.
This should kill all the processes associated with port 8000.
EDIT:
For osx users you can use sudo lsof -t -i tcp:8000 | xargs kill -9
79๐
netstat -ntlp
It will show something like this.
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 6599/python
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp 0 0 192.168.124.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp6 0 0 :::3306 :::* LISTEN
So now just close the port in which Django/python running already by killing the process associated with it.
kill -9 PID
in my case
kill -9 6599
Now run your Django app.
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-Django.contrib.gis.db.backends.postgis vs django.db.backends.postgresql_psycopg2
- [Django]-Extend base.html problem
17๐
ps aux | grep -i manage
after that you will see all process
ubuntu@ip-10-154-22-113:~/django-apps/projectname$ ps aux | grep -i manage
ubuntu 3439 0.0 2.3 40228 14064 pts/0 T 06:47 0:00 python manage.py runserver project name
ubuntu 3440 1.4 9.7 200996 59324 pts/0 Tl 06:47 2:52 /usr/bin/python manage.py runserver project name
ubuntu 4581 0.0 0.1 7988 892 pts/0 S+ 10:02 0:00 grep --color=auto -i manage
kill -9 process id
e.d kill -9 3440
`enter code here`after that :
python manage.py runserver project name
- [Django]-FileUploadParser doesn't get the file name
- [Django]-Django TypeError: get() got multiple values for keyword argument 'invoice_id'
- [Django]-PHP Frameworks (CodeIgniter, Yii, CakePHP) vs. Django
14๐
By default, the runserver command starts the development server on the internal IP at port 8000.
If you want to change the serverโs port, pass it as a command-line argument. For instance, this command starts the server on port 8080:
python manage.py runserver 8080
- [Django]-Add additional options to Django form select widget
- [Django]-Do we need to upload virtual env on github too?
- [Django]-IOS app with Django
- [Django]-Cannot access django app through ip address while accessing it through localhost
- [Django]-How do I match the question mark character in a Django URL?
- [Django]-DRF: custom ordering on related serializers
6๐
>> ps aux | grep manage
ubuntu 3438 127.0.0 2.3 40256 14064 pts/0 T 06:47 0:00 python manage.py runserver
>> kill -9 3438
- [Django]-Allowing only super user login
- [Django]-How do I do an OR filter in a Django query?
- [Django]-How do you configure Django to send mail through Postfix?
5๐
We donโt use this command { sudo lsof -t -i tcp:8000 | xargs kill -9 } Because itโs close all tabsโฆYou should use to
ps -ef | grep python
kill -9 process_id
ps -ef | grep python (show all process with id)
kill -9 11633
(11633 is a process id to :- /bin/python manage.py runserver)
- [Django]-Pagination in Django-Rest-Framework using API-View
- [Django]-Django models: default value for column
- [Django]-Switching to PostgreSQL fails loading datadump
5๐
Type โfgโ as command after that Ctrl-C.
Command:
Fg will show which is running on background. After that Ctrl-C will stop it.
fg
ctl-c
- [Django]-Error: No module named staticfiles
- [Django]-Django testing: Test the initial value of a form field
- [Django]-Fastest way to get the first object from a queryset in django?
5๐
Sorry for comment in an old post but It may help people
Just type this on your terminal
killall -9 python3
It will kill all python3 running on your machine and it will free your all port. Greatly help me when to work in Django project.
- [Django]-Django: Record with max element
- [Django]-Django set default form values
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
4๐
- In terminal, Type
ps aux | grep runserver
- Hit Enter
- Use PID among the result execute
kill -9 <PID>
For an instance, If result of step 1 is as follow
root 1041 0.0 0.1 266912 34580 pts/3 S+ 11:31 0:01 python3 manage.py runserver 0.0.0.0:3030
root 1696 4.5 0.1 126128 40708 ? S Feb14 925:43 /usr/local/bin/python manage.py runserver 0.0.0.0:8000
1041 and 1696 are PIDs. We need to choose whichever process we want to kill among them.
- [Django]-Django 1.8 KeyError: 'manager' on relationship
- [Django]-Django error when installing Graphite โ settings.DATABASES is improperly configured. Please supply the ENGINE value
- [Django]-Removing 'Sites' from Django admin page
2๐
This is an expansion on Mounirโs answer. Iโve added a bash script that covers this for you. Just run ./scripts/runserver.sh
instead of ./manage.py runserver
and itโll work exactly the same way.
#!/bin/bash
pid=$(ps aux | grep "./manage.py runserver" | grep -v grep | head -1 | xargs | cut -f2 -d" ")
if [[ -n "$pid" ]]; then
kill $pid
fi
fuser -k 8000/tcp
./manage.py runserver
- [Django]-*_set attributes on Django Models
- [Django]-Django MEDIA_URL and MEDIA_ROOT
- [Django]-NumPy array is not JSON serializable
2๐
Click the arrow in the screenshot and find the bash with already running Django server. You were getting the message because your server was already running and you tried to start the server again.
- [Django]-What are the limitations of Django's ORM?
- [Django]-How to query as GROUP BY in Django?
- [Django]-How do you configure Django to send mail through Postfix?
1๐
For me, this happens because my API request in Postman is being intercepted by a debugger breakpoint in my appโฆ leaving the request hanging. If I cancel the request in Postman before killing my appโs server, the error does not happen in the first place.
โ> So try cancelling any open requests you are making in other programs.
On macOS, I have been using sudo lsof -t -i tcp:8000 | xargs kill -9
when I forget to cancel the open http request in order to solve error = That port is already in use.
This also, complete closes my Postman app, which is why my first solution is better.
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
- [Django]-Logging in Django and gunicorn
- [Django]-Annotate a queryset with the average date difference? (django)
1๐
Dont use CTRL + Z to stop server, use CTRL + C to stop the server, I had also had the same problem in my linux (fedora) , I used to stop the server using CTRL + Z and again I used to kill the server using sudo fuser -k 8000/tcp command, which worked fine. But later when I started using CTRL + C , I didnot get that port running issue anymore.
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-Django CMS fails to synch db or migrate
- [Django]-Django multiple template inheritance โ is this the right style?
0๐
if you have face this problem in mac you just need to open activity monitor and force quite python then try again
- [Django]-Django: Filter a Queryset made of unions not working
- [Django]-Django url tag multiple parameters
- [Django]-Django annotation with nested filter
0๐
In case You are using the VSCโs screen terminal, The error might be due to the fact that you already runserver in some other shell.
Just click on the dropbox on the left of the + sign in the header of the terminal of VSC and select some other shell and check if the server is already running there. Quit that server and you are ready to launch a another server.
- [Django]-Django: How to get related objects of a queryset?
- [Django]-Django Rest Framework pagination extremely slow count
- [Django]-Django render_to_string missing information
0๐
I was trying all the solutions but they were not working i suggest you to keep press the power button or if your battery is removeable then remove it all the process will be killed and your local host will be reset
- [Django]-How to stop autopep8 not installed messages in Code
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error
- [Django]-Django โ how to visualize signals and save overrides?
0๐
Just past your terminal below the command
lsof -t -i tcp:8000 | xargs kill -9
- [Django]-Multiple annotate Sum terms yields inflated answer
- [Django]-Django AutoField with primary_key vs default pk
- [Django]-How do I get user IP address in Django?