Failed Manage.py runserver command - django

I'm a beginner in web development. I'm using pycharm and django 2.1 framework
I installed django using ('py -m pip install django==2.1') and it is done.
I started myweb project using ('py -m django-admin startproject myweb .') and it also done
but when I try ('manage.py runserver') command, this is the result:
(venv) C:\Users\مرحبا\PycharmProjects\Myweb>manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 27, 2020 - 20:08:58
Django version 3.0.4, using settings 'myweb.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread <bound method Thread.name of <Thread(django-main-thread,
started
daemon 5152)>>:
Traceback (most recent call last):
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 917, in
_bootstrap_inner
self.run()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\management\commands\runserver.py", line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 206, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\site-
packages\django\core\servers\basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socketserver.py", line 449, in
__init__
self.server_bind()
File "C:\Users\مرحبا\AppData\Local\Programs\lib\wsgiref\simple_server.py", line
50,
in server_bind
HTTPServer.server_bind(self)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\http\server.py", line 139, in
server_bind
self.server_name = socket.getfqdn(host)
File "C:\Users\مرحبا\AppData\Local\Programs\lib\socket.py", line 680, in getfqdn
aliases.insert(0, hostname)
AttributeError: 'str' object has no attribute 'insert'
Could you help me please?

In the last line of the error it says
aliases.insert(0, hostname) AttributeError: 'str' object has no attribute 'insert'
Your Aliases variables is a string, not a list, so you can't .insert() to it, as that functionality doesn't exist.
You need to make sure Aliases is a list in your code.

Related

Django - deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver

I am running a linux red hat environment from AWS.
I have followed every instruction for upgrading sqlite3 to the "latest" version.
I am running python 3.9.2 (and have recompiled it with LD_RUN_PATH=/usr/local/lib ./configure) and django version 4.
I have set up a virtual environment to install and run django. I have changed the activate script to include export LD_LIBRARY_PATH="/usr/local/lib"
Upon running python manage.py runserver, I get the error django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher. I have opened the file /home/ec2-user/django/django/db/backends/sqlite3/base.py (where the error occurs) and right after the line with the error have include a print statement:
print("**************************\n" +
str(Database.sqlite_version) +
"\n" + str(Database.sqlite_version_info) +
"\n**************************")
which retruns:
**************************
3.28.0
(3, 28, 0)
**************************
**************************
3.28.0
(3, 28, 0)
**************************
Please let me know what additional information is needed. I have searched up and down the stack and can't find the right solution to pop this one off.
Thank you in advance!
EDIT
Here is the traceback:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/ec2-user/django/django/utils/asyncio.py", 21 in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/sqlite3/base.py", line 210, in get_new_connection
create_deterministic_function('django_date_extract', 2, _sqlite_datetime_extract)
sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/python/lib/python/3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/opt/python39/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/home/ec2-user/django/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/ec2-user/django/django/core/management/commands/runserver.py", line 126, in inner_run
self.check_migrations()
File "/home/ec2-user/django/django/core/management/base.py", line 486, in check_migrations
executor = MigrationExecutor(connectsion[DEFAULT_DB_ALIAS])
File "/home/ec2-user/django/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ec2-user/django/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/home/ec2-user/django/django/db/migrations/loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ec2-user/django/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/home/ec2-user/django/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/home/ec2-user/django/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/home/ec2-user/django/djanog/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/ec2-user/django/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ec2-user/django/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ec2-user/django/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ec2-user/django/django/db/backends/sqlite3/base.py", line 210, in get_new_connection
create_deterministic_function('django_date_extract', 2, _sqlite_datetime_extract)
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
I came across the same issue in my linux Centos7+python3.9.6+Django3.2.5.
Althougt the sqlite3 is updated to the lastest version. It seems that this is useless. A kind of solution is changing the database from sqlite3 to pysqlite3.
After acticate the virtualenv, install pysqlite
pip3 install pysqlite3
pip3 install pysqlite3-binary
and change db in base.py
vim python3.9.6/site-packages/django/db/backends/sqlite3/base.py
# from sqlite3 import dbapi2 as Database # annotation
from pysqlite3 import dbapi2 as Database # import pysqlite3
restart django server and it works.
I have got the same problem as yours. when I tried to deploy on Elastic Beanstalk.
In my case used Python 3.8 when I initialized EB CLI like this:
eb init -p python-3.8 django-project ⛔
and that not a good python version to run it on 64bit Amazon Linux 2 (default). change to python-3.7
eb init -p python-3.7 django-project ✅
It can be solved by recompiling python3 with the correct environment. Below are the commands for recompiling python3.
export C_INCLUDE_PATH=/PATH_TO_SQLITE/include
export CPLUS_INCLUDE_PATH=/PATH_TO_SQLITE/include
export LD_RUN_PATH=/PATH_TO_SQLITE/lib
./configure --prefix=/PATH_FOR_PYTHON
make
make install
Then a check can be done in python by the below commands
import sqlite3
conn = sqlite3.connect(':memory:')
conn.create_function('f', 2, lambda *args: None, deterministic=True)
The best I can figure at the moment is to go into /home/ec2-user/django/django/db/backends/sqlite3/base.py, change the function variable deterministic=True in get_new_connection() to deterministic=False...
This will remove the error, but seems like a super cheaty solution. If anyone has a better fix, please let me know.
Using PostgreSQL is a good choice as it does support python 3.8 and solves this error. Also as in this question is explained that it is better to use postgreSQL for production. Having said that I recommend this tutorial that teaches how to run postgres on eb. Despite it is a bit outdated it was for me very useful.
安装 pip3 install pysqlite3
打开文件/usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py,找到 from sqlite3 import dbapi2 as Database 注释它,替换为from pysqlite3 import dbapi2 as Database
vim /u01/apps/python3/lib/python3.10/site-packages/django/db/backends/sqlite3/_functions.py 将deterministic=True中的函数变量get_new_connection()更改为deterministic=False ..
然后
vim /u01/apps/python3/lib/python3.10/site-packages/django/db/backends/base/base.py# def : check_database_version_supported 里面的方法注释掉 写上pass
如:
def check_database_version_supported(self):
pass
"""
Raise an error if the database version isn't supported by this
version of Django.
"""

Error while Running Python manage.py runserver comman [duplicate]

This question already has answers here:
Unicodedecodeerror with runserver
(3 answers)
Closed 2 years ago.
I have started learning django this was my first tutorial.
First i ran django-admin startproject
This command works according to tutorial but when I run this command
python manage.py runserver
Following Error Occurs but not in tutorial video
*Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
September 27, 2019 - 18:01:04
Django version 2.2.5, using settings 'first.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Exception in thread django-main-thread:
Traceback (most recent call last): File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 917, in _bootstrap_inner self.run() File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\threading.py",
line 865, in run
self._target(*self._args, **self._kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\autoreload.py",
line 54, in wrapper
fn(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\commands\runserver.py",
line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 203, in run
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6) File
"C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\servers\basehttp.py",
line 67, in init
super().init(*args, **kwargs) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socketserver.py",
line 449, in init
self.server_bind() File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\wsgiref\simple_server.py",
line 50, in server_bind
HTTPServer.server_bind(self) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\http\server.py",
line 139, in server_bind
self.server_name = socket.getfqdn(host) File "C:\Users\MuBasHer\AppData\Local\Programs\Python\Python37\lib\socket.py",
line 676, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position
6: invalid start byte *
You need to change hostname in Windows to remove any not UTF-8 characters.
first of all, I assume you are using the windows command-line tool as your shell.
If so, then run the command-line tool as administrator and
cd into your project directory, switch into your working(virtual environment),
then run the python manage.py runserver command again.
With these few steps you can startup your development server.
thanks

SQLite objects created in a thread can only be used in that same thread with Django 2.2.2 and ipdb

I updated my Django project to version 2.2.2 and now when I call to ipdb for debugging, the server tell me that error. If I go back to Django 2.2.1, the error disappears.
System check identified no issues (0 silenced).
June 06, 2019 - 08:19:36
Django version 2.2.2, using settings 'laserapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
> /home/lynde/public_html/laserapp/gestion/views.py(192)get_context_data()
191 import ipdb; ipdb.set_trace()
--> 192 context = super(ResumeOrderCodeView, self).get_context_data(**kwargs)
193 try:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 288, in run
self.run_loop()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 294, in run_loop
next(ticker)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 120, in iter_modules_and_files
sys_file_paths.append(module.__file__)
AttributeError: module '__main__' has no attribute '__file__'
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 780, in writeout_cache
self._writeout_input_cache(conn)
File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 764, in _writeout_input_cache
(self.session_number,)+line)
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140030717908736 and this is thread id 140031011022656.
Can somebody know what's the problem there? I'm using django runserver in local machine, with celery and postgresql database.
Thanks!! :)
Try using the --reload flag to run runserver.
./manage.py runserver --noreload
It stops the server reloading on code changes but I think avoids the issue you're having.

AttributeError: 'NoneType' object has no attribute 'tags'

Traceback (most recent call last):<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/cherrypy.wsgiserver.wsgiserver2", line 1353, in communicate<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/cherrypy.wsgiserver.wsgiserver2", line 868, in respond<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/cherrypy.wsgiserver.wsgiserver2", line 2267, in respond<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/cherrypy.wsgiserver.wsgiserver2", line 2477, in __call__<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.core.handlers.wsgi", line 206, in __call__<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.core.handlers.base", line 194, in get_response<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.core.handlers.base", line 229, in handle_uncaught_exception<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.views.debug", line 69, in technical_500_response<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.views.debug", line 322, in get_traceback_html<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.template.base", line 125, in __init__<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.template.base", line 152, in compile_string<br/>
File "home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.template.debug", line 35, in __init__<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.template.base", line 239, in __init__<br/>
File "/home/rpmbuild/venv/build/pyi.linux2/MF/out00-PYZ.pyz/django.template.base", line 353, in add_library<br/>
AttributeError: 'NoneType' object has no attribute 'tags'
I have pyinstaller for django project running on cherrypy server.
its working from python manage.py runserver from command prompt
not working using bundled through pyinstaller.
I have tested for both development environment and production environment in settings.py
DEBUG = False/True<br>
Allowed_HOSTS = ['*']
Somewhere you use the code like this:
<something>.tags
where is estimated to None
If you use django.contrib.markup.templatetags.markup so this is the problem, because django.contrib.markup.templatetags.markup is depricated

PyCharm manage.py runserver error

Sorry to ask a noob question but I have no idea why this is happening.
I've just reinstalled Django 1.3, and am trying PyCharm for the first time. When I run python manage.py runserver from Terminal everything goes without a hitch, however if I try to runserver from within PyCharm I get the following:
Importing Django settings module settings
Traceback (most recent call last):
Validating models...
0 errors found
Django version 1.3, using settings 'glist.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
File "/Applications/PyCharm 1.2.1.app/helpers/pycharm/django_manage.py", line 19, in <module>
run_module(manage_file, None, '__main__')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
fname, loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/goon/code/glist/manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 76, in run
autoreload.main(self.inner_run, args, options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 131, in main
reloader(main_func, args, kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 104, in python_reloader
reloader_thread()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 83, in reloader_thread
ensure_echo_on()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 77, in ensure_echo_on
attr_list = termios.tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
Process finished with exit code 1
Please note that this is all happening before I request any page from within the browser. And, as I said, I have no trouble running from Terminal. Any help would be greatly appreciated.
What version fo pycharm are you using ? Actually it`s a error in django 1.3. It will occur if you try to run django from any ide in reload mode. It can be fixed by patching django. Although PyCharm should automatically switch to no reload mode.
Read this : http://blogs.jetbrains.com/pycharm/2011/03/pycharm-1-2-1-release-candidate-py-test-2-0-buildout-1-5/
Apply the patch. Its Django 1.3.1 error. This worked for me on pYCharm 3.4.1
https://github.com/django/django/commit/3e7ce3c750