Restart Django Python server

Asked

Viewed 72 times

-1

Hello! I’m starting in the world of programming, through a book called "Intensive Python Course". One of the book’s projects involves creating a virtual environment to use Django. I was able to configure everything correctly (the parts that were different from what was in the book, I found the answer on the internet) and started the server. In this project is created a small database (through Sqlite) and some records were made.

Everything went fine until the server I had started by Windows Powershell crashed. The command I used to startar the server was: python Manage.py runserver. This file Manage.py is at the root of the project and everything is ok.

The only problem is that after a while without doing some process in the other Powershell window (where I type the commands), the server went offline, which obviously also knocked down access to localhost:8000 (I expected this behavior). My virtual environment in Django is called ll_env. Then I used the command ll_env Scripts Activate to access the virtual environment and then tried to restart the server with the previous command (python Manage.py runserver) but it does not work. It is as if the file Manage.py was no longer recognized and Shell returns the error below.

Does anyone know please how to restart the server or if there is any configuration so that the server does not fall?

Watching for file changes with Statreloader Exception in thread Django-main-thread: Traceback (Most recent call last): File "C: Python38 lib threading.py", line 932, in _bootstrap_inner self.run() File "C: Python38 lib threading.py", line 870, in run self. _target(*self.args, **self.kwargs) File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django utils autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django core management Commands runserver.py", line 110, in inner_run autoreload.raise_last_exception() File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django utils autoreload.py", line 76, in raise_last_exception raise Exception[1] File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django core management_init.py", line 357, in execute autoreload.check_errors(Django.setup)() File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django utils autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django_init.py", line 24, in setup apps.populate(Settings.INSTALLED_APPS) File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django apps Registry.py", line 114, in populate app_config.import_models() File "C: Users Marlo Pycharmprojects learning_log ll_env lib site-Packages Django apps config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "C: Python38 lib importlib_init.py", line 127, in import_module Return _bootstrap. _gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C: Users Marlo Pycharmprojects learning_log learning_logs models.py", line 16, in class Entry(models.Model): File "C: Users Marlo Pycharmprojects learning_log learning_logs models.py", line 18, in Entry topic = models.Foreignkey(Topic) Typeerror: init() Missing 1 required positional argument: 'on_delete'

1 answer

0

"TypeError: init() missing 1 required positional argument: 'on_delete'"

This means that on line 18 of your file py.models is missing an argument *on_delete* which refers to a foreign key

you probably have something like this:

class AlgumModelo(model.Model):
    
    topic = models.ForeignKey(Topic) 

and you need to add the 'on_delete'

class AlgumModelo(model.Model):
    
    topic = models.ForeignKey(Topic, on_delete=models.CASCADE)

you can use other functions, one of them pro on_delete is on_delete=models.DO_NOTHING

fixing this problem, you can restart the server

  • Show!! It worked! I used on_delete=models.DO_NOTHING. In fact, I didn’t have that in the models.pyfile. I will take this opportunity to deepen the studies of this part related to the database. Thank you very much :)

  • Before you delve into qlqr thing, you need to learn to understand the logic of error messages. It usually says what you need to do, or gives you a clue as to what you might be causing. Probably those who denied you the question, think you did not try hard to understand the mistake, but tmb did not come to tell you this. Patience. Don’t give up

Browser other questions tagged

You are not signed in. Login or sign up in order to post.