I just installed django and after installing that I created a django project and was trying to run django server by command:
python manage.py runserver
After that I'am getting error as:
SyntaxError: Generator expression must be parenthesized
TL; DR: Upgrade Django to version 1.11.17+ or 2.0+
This error is a known incompatibility related to Python issue #32012. Projects based on Django 1.11.16 and below will raise this exception when started with Python 3.7. A patch for this issue has been merged into Django 2.0 and 2.1 branches and cherry-picked later into Django 1.11.17.
Note: Python 3.7 is officially supported by Django 1.11.17 and above, including any 2.x branch.
Generator expression must be parenthesized
> Update Django version to 1.11.17
pip install django==1.11.17
Had same issue. This is how I changed to django version 2.0 and used python3
$pip3 install django==2.0
$python3 manage.py runserver
Install this version: pip install django==1.11.17
Run cmd.
go to your project folder.
python manage.py runserver
it will give a URL for server and you are good to go.
This is due to the version incompatibility.Just we need to upgrade the Django version to 2.1.
Run the command in cmd:Pip install django==2.1. this will resolve the issue
I just faced an Error like this. I was using Django-1.11.10. I deleted it and installed Django 2.0
Problem is solved.
But if you are using ForeignKey in you model.py files it must be problem again. You should update your coding to 2.0 versiong insted of older versiyon.
Example:
django older version
user = models.ForeignKey('auth.User', related_name='posts')
django 2.0
user = models.ForeignKey('auth.User', related_name='posts', on_delete=models.CASCADE,)
I had the same issue and I realized it is due to the compatibility of the Django version I was working with. So I had to state the Python version explicitly like this: >python3.6 manage.py runserver
Just open file:
venv/lib/python3.7/site-packages/django/contrib/admin/widgets.py
and replace the lines
related_url += '?' + '&'.join(
'%s=%s' % (k, v) for k, v in params.items(),)
with
related_url += '?' + '&'.join('%s=%s' % (k, v) for k, v in params.items())
Related
I'm trying to set up a repo locally but facing an issue i.e python manage.py runserver command gets aborted as soon as I hit localhost URL (http://127.0.0.1:8000/)
error - [1] 7398 abort python manage.py runserver
Django version 1.6.6
Python 2.7
OS -> MacOS Catalina (10.15.3)
Database postgres (PostgreSQL) 12.2
first why ur using old version python and Django. that's first because they didn't have support so I strongly recommend you to upgrade newest versions
I think this is due to Python & Catalina incompatibility. Try using Python 3.7. Similar question
In general, try to avoid using Python 2.x. Insted use Python 3.7.x.
TL;DR: python versions conflicts, i think that the python i downloaded and compiled (3.6) can't use this package (libmysqlclient-dev) to make migrations to mysql. only the system's default python (3.4) can.
my ubuntu server came with python 3.4, all of my django work and other work depend on 3.6. i have learned that upgrading system python is a bad idea, so i compiled python 3.6 (with altinstall).
when i ran python3.6 manage.py migrate it gave me this mysql error:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1")
i tried virtual environment and normal python 3.6, both gave the same error, and i made sure that libmysqlclient-dev and mysqlclient are installed.
as this answer suggests, the problem is with libmysqlclient-dev because it's installed via apt-get not pip so i guess it's only compatible with the default python (3.4 that came with the system) or my compiled python 3.6 isn't allowed to use it, because when i made a dummy django project with python3.4 (system's default) and attempted python3.6 manage.py migrate on the same mysql database with the same user, it worked!
AGAIN: my problem is that the manually compiled python 3.6 can't use libmysqlclient-dev that has been installed by apt-get, only 3.4 can
reference: Django MySQL error on migrate
UPDATE
i came up with a work around but it's not efficient. i downgraded Django to 2.0.9 and it (python manage.py migrate) worked. but this problem could appear again with a different package.
Django 2.1.* requires MySQL 5.6 or higher. It broke the compatibility by mapping DateTimeField to datetime(6).
You can patch Django MySQL data type mapper. Put this to the top of your settings.py
from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField'] = 'datetime' # fix for MySQL 5.5
There is a major difference in the support for django 2.0.* vs django 2.1.*
AS per Django 2.0.* MySQL Notes
Django supports MySQL 5.5 and higher.
As per Django 2.1.* MySQL Notes
Django supports MySQL 5.6 and higher.
Check you MySQL version with: mysql -V and use the correct django version.
from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.data_types['DateTimeField'] = 'datetime' # fix for MySQL 5.5
Solved my problem!
Thanks Luka Zakrajšek
I want to see the django version in my Pycharm terminal, but I don't get the correct method.
I tried bellow methods in pycharm terminal:
1) django --version and django version
2) import django, and print the version by:
import django
print django.VERSION
But I still can not get it.
If you cannot print the Django version from the python console in Pycharm, go to settings>Project:project_name>project Interpreter and from the list of installed packages see the installed Django and it's version for that project.
You can run pip freeze too. Just filtering the results with grep...
pip freeze | grep Django
You're trying to access a version attribute, but you can find out Django's version using the get_version method:
import django
django.get_version()
In the terminal you can use bellow command to check the version of django:
python -m django --version
If you want to use your second method, just like this bellow command:
python -c "import django; print(django.VERSION)"
(1, 11, 2, u'final', 0)
go to setting > project > project Interpreter and install Django package
then run the code
import django
print(django.get_version())
Run pip freeze > requirements.txt
A .txt file with that name will be created automatically, open the file and check for the django version and other previously installed libraries.
I do not know about pychram but the most efficient way to query the django version without importing django globally would be this:
from django import VERSION as DJANGO_VERSION
if DJANGO_VERSION >= (2, 0):
pass
What was not proposed in this question which is something similar:
How to check Django version
I had the same question. The solution is simple.
Just create a project, open settings.py file and observe the first comment lines. You will see the version info in there as displayed below:
Image of settings.py that shows the Django version
I found the solution here.
Simplest is
import django
print(django.get_version())
Using the following command on terminal will give you django version
python -m django --version
Or
You can go to the interactive python prompt and use the command
import django
print(django.get_version())
or using pip freeze and grep you can also get the django version
pip freeze | grep Django
I have installed on Win7 portable Python 2.7.5.1 and Django 1.6.
I followed the first polls tutorial instructions and got an error in the migrate stage, python manage.py migrate:
C:\Natan\Dev\Portable Python 2.7.5.1\App\Scripts\mysite>..\..\python.exe manage.py migrate
Unknown command: 'migrate'
Type 'manage.py help' for usage.
Any idea?
If you've installed 1.6, you should use the 1.6 tutorial, not the one for the development version.
First Step, Install South:
pip install south
Second Step, Add South to INSTALLED APPS in settings
INSTALLED_APPS = (
...,
'south' )
Migrate will be a native command in 1.7 (which is the version you read the tutorial pages from).
For older versions, you'll have to install the third party app"South".
All-
This is likely caused largely by following the 1.7 (DEV version!) tutorial when we all get the last stable version (1.6!) installed by pip.
It would not appear migrate is even a part of 1.7 in general! Will:
python manage.py syncdb
Solve your problems?
So pls either follow the tutorial for the last stable version of django: https://docs.djangoproject.com/en/1.6/intro/tutorial01/
Or follow the instructions to install the dev version of Django.
Dear Django team,
You guys are awesome. The JS developer is very impressed. But PLEASE resolve the discrepancy above. Maybe default to 1.6 docs and put in red letters: Dev version here?
Thank you.
You must install South to add migrate command.
pip install south
If you are using Django older versions before 1.7 then you should sync database by
python manage.py syncdb
while in new versions after 1.7 syncdb is replaced by migration. So for syncdb in new django version is replaced by :-
python manage.py makemigrations
python manage.py migrate
for more type:-
python manage.py help
Super simple question: I went through the "getting start" doc for haystack (using whoosh; I installed both python-whoosh and haystack using pip (first time using it)), and I simply cannot run python manage.py rebuild_index. I get this error:
python manage.py rebuild_index
Unknown command: 'rebuild_index'
Type 'manage.py help' for usage
I do have 'haystack' listed in my INSTALLED_APPS in settings.py, so this solution doesn't seem to work for me. I also don't get import errors when I run "import haystack" so it does exist. I tried this on my existing project as well as a brand new object made just for this and I just can't get it to work.
However, when I import haystack after python manage.py shell and try haystack.__version__ I get "AttributeError: 'module' object has no attribute 'version'". I get a similar error if I try haystack.management: it has no management attribute.
It must be something super simple I'm missing. Thank you for reading this!
Did you perhaps install the wrong thing? This (embarrassingly) happend to me just today. Make sure you install 'django-haystack' and not just 'haystack' (and you will have to remove 'haystack', since it conflicts with 'django-haystack').
Do you have the path to haystack in your Python path? (Either the PYTHONPATH shell variable or the sys.path Python list.)
Did you run python manage.py syncdb?
Does python manage.py shell followed by import haystack work?
After import haystack, what do you get for haystack.__version__?
In the same shell, type the following. Do you get errors for any of them?
haystack.management.commands
haystack.management.commands.rebuild_index
haystack.management.commands.rebuild_index.Command.help
I had the same error that you did, and fixed it by removing the old .egg and installing directly from the latest version. You can use easy_install:
easy_install https://github.com/toastdriven/django-haystack/zipball/v1.2.4
Hope this helps!
I had the same problem - for whatever reason, the haystack version in pip is quite old and obsolete (v 0.6 as of today). To use django-haystack check out the v1. source.
It compiles and installs simply with
python setup.py build
python setup.py install
Hope that helps!
I just had the same problem and hadn't set HAYSTACK_SITECONF in my settings.py.
Instead of using python manage.py rebuild_index try using ./manage.py rebuild_index
just do
pip uninstall haystack and
pip install django-haystack