This is an article where the content in it is focusing on how to solve an error message. The error actually exist after executing a command. The command is a command to start a Django-based web application. The following is the execution of that command :
(myenv) C:\python\project\apps>python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). December 12, 2020 - 14:19:07 Django version 3.1.4, using settings 'apps.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. Internal Server Error: /app/employee-add Traceback (most recent call last): File "C:\python\myenv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\python\myenv\lib\site-packages\django\core\handlers\base.py", line 202, in _get_response response = response.render() File "C:\python\myenv\lib\site-packages\django\template\response.py", line 105, in render self.content = self.rendered_content File "C:\python\myenv\lib\site-packages\django\template\response.py", line 81, in rendered_content template = self.resolve_template(self.template_name) File "C:\python\myenv\lib\site-packages\django\template\response.py", line 63, in resolve_template return select_template(template, using=self.using) File "C:\python\myenv\lib\site-packages\django\template\loader.py", line 47, in select_template raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain) django.template.exceptions.TemplateDoesNotExist: app/employee_form.html [12/Dec/2020 16:15:56] "GET /app/employee-add HTTP/1.1" 500 79963 Not Found: /favicon.ico ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 3729) Traceback (most recent call last): File "C:\Python38\lib\socketserver.py", line 650, in process_request_thread self.finish_request(request, client_address) File "C:\Python38\lib\socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "C:\Python38\lib\socketserver.py", line 720, in __init__ self.handle() File "C:\python\myenv\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle self.handle_one_request() File "C:\python\myenv\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request self.raw_requestline = self.rfile.readline(65537) File "C:\Python38\lib\socket.py", line 669, in readinto return self._sock.recv_into(b) ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine ----------------------------------------
The main error appears in the error message above. The first one is an error message as in the following line :
Internal Server Error: /app/employee-add
The other error message appear which is helping to focus on how to solve the error is in the following line :
django.template.exceptions.TemplateDoesNotExist: app/employee_form.html
The first error message is hinting that there is something wrong while accessing the URL of ‘/app/employee-add’. The definition of the URL exist in the file of ‘urls.py’ in the app folder. The following is the definition of the URL :
path('employee-add',views.EmployeeCreateView.as_view(),name='employee-add'),
So, in order to further inspect the cause of the error, just check the views.py file. Specifically the EmployeeCreateView class as follows :
class EmployeeCreateView(CreateView): model = Employee fields = ['name','id_employee']
The main concern is that there must be a file with the name of ’employee_form.html’ exist in the folder of the application. So, create one file with that name. The following is the location of the file :
C:\python\project\apps>tree . Folder PATH listing for volume Windows Volume serial number is E003-3593 C:\PYTHON\PROJECT\APPS ├───apps │ └───__pycache__ └───app ├───migrations │ └───__pycache__ ├───templates │ └───guestbook | └───employee_form.html └───__pycache__ C:\python\project\apps>
After creating the above file, just re-execute the command for starting the Django-based web application. The following will appear :
(myenv) C:\python\project\apps>python manage.py runserver Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). December 12, 2020 - 17:15:08 Django version 3.1.4, using settings 'apps.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. [12/Dec/2020 17:15:12] "GET /apps/employee-add HTTP/1.1" 200 2257