python manage.py runserver fails - python

I am trying to learn django by following along with this tutorial. I am using django version 1.1.1
I run
django-admin.py startproject mysite
and it creates the files it should. Then I try to start the server by running
python manage.py runserver
but here is where I get the following error.
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 213, in execute
translation.activate('en-us')
File "/Library/Python/2.6/site-packages/django/utils/translation/__init__.py", line 73, in activate
return real_activate(language)
File "/Library/Python/2.6/site-packages/django/utils/translation/__init__.py", line 43, in delayed_loader
return g['real_%s' % caller](*args, **kwargs)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 205, in activate
_active[currentThread()] = translation(language)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Python/2.6/site-packages/django/utils/translation/trans_real.py", line 172, in _fetch
for localepath in settings.LOCALE_PATHS:
File "/Library/Python/2.6/site-packages/django/utils/functional.py", line 273, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'LOCALE_PATHS'
Now, I can add a LOCALE_PATH atribute and set to an empty tuple to my settings.py file but then it just complains about another setting and so on. What am I missing here?

Something is broken in your django installation. maybe you have a (very) old version somewhere in the path?
LOCALE_PATHS was given a default value in the global settings file a long time ago.

Can't really explain that. Try removing the project directory and starting again.
Are you definitely running the manage.py from within the directory with the settings file?

Related

Problem with Django startproject: TypeError: '_sre.SRE_Match' object is not subscriptable

Trying to run
django-admin startproject mysite
and there occurs such problem
Traceback (most recent call last):
File "/Users/username/Desktop/test/venv/bin/django-admin", line 10, in <module>
sys.exit(execute_from_command_line())
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/commands/startproject.py", line 20, in handle
super().handle('project', project_name, target, **options)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/templates.py", line 158, in handle
template = Engine().from_string(content)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/engine.py", line 136, in from_string
return Template(template_code, engine=self)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 155, in __init__
self.nodelist = self.compile_nodelist()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 193, in compile_nodelist
return parser.parse()
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 447, in parse
filter_expression = self.compile_filter(token.contents)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 563, in compile_filter
return FilterExpression(token, self)
File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 638, in __init__
var, constant = match['var'], match['constant']
TypeError: '_sre.SRE_Match' object is not subscriptable
I guess there is a problem with versions, but don't know exactly what is it.
On version 1.8.6 everything is ok, but when I try to use
from django.urls import path, include
I see that there is no django.urls in this version.
So I'd like to use the latest version and will be grateful, if you can help me!
Python version:
Python 3.6.0a4
It seems that you use an unofficial version of django.
Hello, try this first, dont remove anything leave pip do it for you:
pip install -U django
Now After that rerun startproject command line

how can i solve AttributeError 'NoneType' object has no attribute 'write'

python manage.py migrate
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\migrate.py", line 162, in handle
self.stdout.write(self.style.MIGRATE_HEADING("Operations to perform:"))
File "C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 145, in write
self._out.write(style_func(msg))
AttributeError: 'NoneType' object has no attribute 'write'
please can anyone help out with this error.
it popup anytime i try to use manage.py. anyone please
You can go to Migrations folder and delete all the files other then init.py
and then run the
python manage.py makemigrations
python manage.py migrate
I have exactly the same problem (Python 3.7 and django 1.10). Turns out the problem was that it was running on the bash (from git bash). I guess it errors trying to get stdout.
It works using Windows's command prompt.

Django Error when running server locally - AttributeError: 'list' object has no attribute 'read'

Getting below error when trying to run server in VS Code for Django.
Command: python manage.py runserver
Error:
C:\DjangoServerTest\DjangoServerTest>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 601, in run_with_reloader
exit_code = restart_with_reloader()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 230, in restart_with_reloader
p = subprocess.run(args, env=new_environ, close_fds=False)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\site-packages\run\__init__.py", line 121, in create_process
shlex.split(command),
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 305, in split
return list(lex)
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 295, in __next__
token = self.get_token()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 105, in get_token
raw = self.read_token()
File "C:\Users\subhasispanda\AppData\Local\Programs\Python\Python37-32\lib\shlex.py", line 136, in read_token
nextchar = self.instream.read(1)
AttributeError: 'list' object has no attribute 'read'
Can you please help here?
I too had the same issue.
What i did is that i went to control panel -> search -> advanced system settings ->environment variables -> Path
then cleared all paths
Uninstalled python, and deleted all the python related files in the "C:\Users{user_name}\AppData\Local\Programs" directory
And then downloaded the latest one and installed again.
Then added the scripts folder and the python folder directory into the PATH.
Then installed pip and then django.
Now its woking perfectly.
In short remove all the versions of python completely and then install it again. Also clear all the unwanted "paths" in the environment variables.....
I spent around 2 hours on the same issue that I was facing.
I could not understand why the error is occurring but I found the solution by simply uninstalling python and re-installing it.
In my case I had more than 1 number of python versions installed so I deleted all the 'site-packages' folder too and installed the latest version of python again and it worked.
Let me know if this works for you too.
I had the same Error AttributeError: 'list' object has no attribute 'read' in Django, I uninstalled a package called "subprocess.run" with "pip uninstall [package-name]" and that's all. You can run your project

django-admin.py makemessages fails

I had created language-files with django-admin.py makemessages -a
A little bit development later all attempts to create *.po files are failing with:
django-admin.py makemessages -v 3 -a
examining files with the extensions: .html and .txt
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 283, in handle_noargs
potfiles = self.build_potfiles()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 299, in build_potfiles
file_list = self.find_files(".")
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 358, in find_files
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemessages.py", line 358, in <listcomp>
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/usr/lib/python3.4/posixpath.py", line 335, in normpath
initial_slashes = path.startswith(sep)
AttributeError: 'NoneType' object has no attribute 'startswith'
I tried it with several file extensions and -ignore patterns.
Do you have any hints?
I have had the same problem since django 1.7. I use manage.py to make messages instead of django-admin.py excluding the environment folder:
python manage.py makemessages --locale=en --ignore=venv/*
This is due to a bug introduced in Django 1.7.1. You can fix this by updating your Django to the latest version using:
pip install -U django
P.S. Related StackOverflow questions and answers on this matter can be found here and here.

Django failing to find apps

I have been working on a django app on my local computer for some time now and i am trying to move it to a mediatemple container and im having a problem when i try to start up django. it gives me this traceback:
application failed to start, starting manage.py fastcgi failed:Traceback
(most recent call last): File "manage.py", line 11, in ?
execute_manager(settings) File
"/home/58626/data/python/lib/django/core/management/__init__.py", line 340,
in execute_manager utility.execute() File
"/home/58626/data/python/lib/django/core/management/__init__.py", line 295,
in execute self.fetch_command(subcommand).run_from_argv(self.argv) File
"/home/58626/data/python/lib/django/core/management/base.py", line 192, in
run_from_argv self.execute(*args, **options.__dict__) File
"/home/58626/data/python/lib/django/core/management/base.py", line 210, in
execute translation.activate('en-us') File
"/home/58626/data/python/lib/django/utils/translation/__init__.py", line
73, in activate return real_activate(language) File
"/home/58626/data/python/lib/django/utils/translation/__init__.py", line
43, in delayed_loader return g['real_%s' % caller](*args, **kwargs) File
"/home/58626/data/python/lib/django/utils/translation/trans_real.py", line
209, in activate _active[currentThread()] = translation(language) File
"/home/58626/data/python/lib/django/utils/translation/trans_real.py", line
198, in translation default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/58626/data/python/lib/django/utils/translation/trans_real.py",
line 181, in _fetch app = getattr(__import__(appname[:p], {}, {},
[appname[p+1:]]), appname[p+1:]) AttributeError: 'module' object has no
attribute 'web'
The name of the first app is "web".
Steps I would take would be
Run the dev server on your Media Template instance. If that runs successfully, it obviously is an error with your apache/nginx/whaever setup.
I dont have experience running apps as FCGI, which it looks to em you are trying to do. It looks to me that somehow when Fcgi runs, it is unable to find your apps. So this is possibly a PYTHONPATH issue. Log/Print sys.path from your fcgi script and look there.

Categories

Resources