Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to treat CMS fields that support HTML [Django]
I have a Django site with a Post object like so: class Post(models.Model): title = models.CharField(max_length=100,blank=True,null=True) body = models.TextField(blank=True,null=True) author = models.ForeignKey(User,blank=True,null=True) date_created = models.DateTimeField(default=timezone.now) date_updated = models.DateTimeField(auto_now_add=True) image = models.ImageField(upload_to=post_dir, blank=True, null=True) def __unicode__(self): return unicode(self.date_created.strftime('%Y-%m-%d %H:%M') + ' ' + self.title) which outputs body TextField like so in order to support HTML: {% if post.body %} <p> {{ post.body | safe }} </p> {% endif %} My question is, since the admins can input HTML which could potentially malform the html (such as post.body = '</div></div>'), what is the best way to format and sanitize this textfield while still allowing users to input html? -
How to add the last_login_ip, when the user login if using `rest-auth`?
How to add the last_login_ip, when the user login if using rest-auth? Befor ask the post I searched one post bellow: How can I do my logic in `http://127.0.0.1:8000/rest-auth/login/` of `django-rest-auth`? The answer is perfect for custom verify the login params. But, how about after login, then add attribute to the User? I mean, the answer is just for verify the data, I want to after user login success, I want to add the last_login_ip to the user instance. -
Any remaining kwargs must correspond to properties or virtual fields - what does it mean?
I was trying with different model relationships, when came across this exception (please write if you want to see the full traceback): File "C:\Users\1\vat\tpgen\tpgen\src\generator\views\wizard.py", line 172, in get_next_form return step, form_type(**kwargs) File "C:\Users\1\vat\tpgen\venv\lib\site-packages\django\db\models\base.py", line 495, in __init__ raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg) TypeError: 'data' is an invalid keyword argument for this function As I understand, the exception was raised when Django tried to create a new instance with some kwargs. The traceback points to Models’ __init__ method in django.db.models.base if kwargs: property_names = opts._property_names for prop in tuple(kwargs): try: # Any remaining kwargs must correspond to properties or # virtual fields. if prop in property_names or opts.get_field(prop): if kwargs[prop] is not _DEFERRED: _setattr(self, prop, kwargs[prop]) del kwargs[prop] except (AttributeError, FieldDoesNotExist): pass for kwarg in kwargs: raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg) The kwargs seems to be all right (printed from the line 171 of wizard.py): {'data': None, 'prefix': '2', 'initial': {'0': {'0-trans_type': ['13'], '0-end_of_tax_year': ['']}, '1': {'1-funct_title': ['14']}}} So the problem, as I understand it, lies in the model, which I admit is a bit overcomplicated, but as said before, I was experimenting with models relationships. The … -
A worker run more than one task when I use django-celery which be control by supervisor
As I know, if I start a work with no -c and it would start "Number of child processes processing the queue. The default is the number of CPUs available on your system." like the document say. http://docs.celeryproject.org/en/latest/reference/celery.bin.worker.html#cmdoption-celery-worker-c Now I had a system ,the number of CPUS is 1. When the project run a long time,I found this: the worker_0 run five process? So many RECEIVED status. Then, the system become slowly very much. Some others say, I may should add -c to limit the number,but, the default should be 1, also would not come like this? E,en,the system is a ECS from a-li. The question: Could some one explain the reason of the phenomenon? The way to solve the problem is not necessary, of course, better if can solve it. -
What is django session? Where the session data is stored?
I am new to django session. I hope you can help me. In my django application, i just have used django session for storing user type data type1 or type2 request.session['user']='type1'. I have used default database backend for session. I have a couple of doubts. 1, Where the data is stored. If the data is stored in database, why i can't access this session from different locations? 2, Basically, a session is related to the login user only? 3,How can i access this data through direct sql queries? -
JQuery talking to DJango REST API. Need to return number of pages in response
Am new to Django REST framework. I have an application that has a listings page. When page is loaded, JQuery should talk to API and when response received it should display a list of available entertainers, which I need paginated. I have pagination working but currently have the number of page links hard coded. I need the either the total number of records or the number of pages returned in the response from the API so that I can dynamically build the links in the template I have tried it a few ways but have not been successful Firstly by passing in Response from my views.py which uses a Class based view if self.request.GET['page'] is not None: if self.request.GET['page'] != 'all': page = self.request.GET['page'] recordsPerPage = 8 paginator = Paginator(entertainers, recordsPerPage) total_records = paginator.count num_pages = paginator.num_pages entertainers = paginator.page(int(page)) return Response({ 'count': paginator.count, 'num_pages': paginator.num_pages, 'results': serialized_data }) This produced an "Internal Server Error" The other way I tried to do it was to add in a custom field in my serializers.py file but it also gave an Internal Server error class EntertainerSerializer(serializers.ModelSerializer): my_field = serializers.SerializerMethodField('record_count') def record_count(self, foo): return foo.name == "10" class Meta: model = Entertainer fields … -
Speed up model property of _set in Django
I have a relatively simple setup with a string of Parent->Child relationships. **Parent Child** Site BU BU CT CT Line Line WS WS Assess So each child has models.ForeignKey(Parent) The business logic is structured like a pyramid. Line's level (1-2-3) is dependent on all of it's childs WS level. A CT's level is dependent on all of it's line's level. BU's level on CTs level Site on BUs level. For example: WS1 \ WS2 - line 1 -- CT 1 -\ WS3 / / \ line 2 -/ \ CT 2 -- BU 1 -\ .. Site 1 .. CT 3 -- BU 2 -/ .. line 9 -- CT 4 -/ line 10 -/ Here's the issue: Each level has a property to set the color. Asking for the Site color (top of the pyramid) initiates 1266 queries on my development database with a minimum amount of dummy data. That is a huge amount. Does anyone know how to better model the color property? It is taking a 4+ seconds to get the site color on a production server with only a few sites, with the intent of adding many additional ones. model.py excerpt: class CT(models.Model): name = models.CharField(max_length=255, … -
Rendering dynamic variable in a django template
I am trying to render dynamic Url in Django template as follows <a href={{'jibambe_site_detail/'|add: site.id}}>{{ site }}</a>. This however is returning a TemplateSyntaxError at /jibambe_sites/ add requires 2 arguments, 1 provided. What am I missing or how should I render this dynamic URL, I want it to produce something like jibambe_site_detail/1 -
cloning project from github but manage.py runserver doesn't work
So I tried cloning a project that I contribute to in Github. But, when I tried to run python manage.py runserver, it showed me the following error Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "C:\Users\CLAIRE\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line utility.execute() File "C:\Users\CLAIRE\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 317, in execute settings.INSTALLED_APPS File "C:\Users\CLAIRE\Anaconda3\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__ self._setup(name) File "C:\Users\CLAIRE\Anaconda3\lib\site-packages\django\conf\__init__.py", line 43, in _setup self._wrapped = Settings(settings_module) File "C:\Users\CLAIRE\Anaconda3\lib\site-packages\django\conf\__init__.py", line 106, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "C:\Users\CLAIRE\Anaconda3\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'now' Can someone please help me, please -
How to get two django rest framework to communicate with each other
So i have 2 django project. Both have its seperated database and table. I create the django rest framework api for both project but i want both of them to communicate with each other. In django 1 is about the social media and medical record app API. In django 2 is a clinic app API where the it is for staff of the clinic and collect user information from django 1 and to give a queue number for user that make appointment. What im trying to do is django 2 will have a qr code for django 1 to scan. After scanning, it will ask for permission to allow their information to be share with django 2(their user information/medical record). After user allow, their information will be save to django 2 database. For now, i just want to allow django 2 to save the user information from django 1. Is there a way for 2 different django project to communicate with each other through the api ? -
Run Background Task in Django (Threading)
I declared a class inherited threading.Thread in django which requests a url and saves an object according to and it works perfect on my computer but when i uploaded to server, Thread was just working makes a response to my main request and after that, thread destroys AddModelThread(movie_id).start() executes when i request the server and after my response the thread destroys! in my Thread i request a website(using requests class python) then i save an object -
Django admin not working?
I just setup a new server on Digital Ocean. Updated Django to 1.11, uploaded my project, ran collectstatic and I've made sure my settings match another project I have (which is live and works 100%). However, my static doesn't collect correctly into my static folder (which I have it set to do), any media I upload wont display, and the admin still has the all design from before I updated it to 1.11... Any thoughts? settings code below.. INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.flatpages', 'listings', 'stats', 'users', 'allauth', 'allauth.account', 'allauth.socialaccount', ) ... STATIC_ROOT = os.path.join(BASE_DIR,'static') STATIC_URL = '/static/' STATICFILES_DIRS = [ '/static/', ] #MEDIA MEDIA_ROOT = '/home/django/django_project/media/' MEDIA_URL = '/media/' Also here's a picture of my file structure: Note that admin did not collect in static -
Updating an UserProfile in Djanngo 1.11
I'm a new developer and I was wondering if you could help me out, updating the values of my User/UserProfile through an editing form. I didn't know at the beginning but now I know I could have extended the (default) User Model and by doing that avoiding creating a new Model UserProfile for the profile purpose and making things simpler (e.g. using generic views). Since I'm still learning I have decided to try a workaround to push myself into thinking instead of appealing to a complete solution. But now I'm stuck for a few days and decided to ask you for some help. I had already looked for similar questions here and in Django's official documentation, but since I didn't follow a specific recipe, I couldn't find something to fix it properly. That's what I've got so far: models.py class UserProfile(models.Model): GENDER_CHOICES = ( ('M', 'Masculino'), ('F', 'Feminino') ) user = models.OneToOneField(User, on_delete=models.CASCADE) profile_image = models.ImageField(upload_to='uploads/', blank=True, null=True) gender = models.CharField(max_length=40, blank=True, null=True, choices=GENDER_CHOICES) birthday = models.DateField(blank=True, null=True) address = models.TextField(max_length=300, blank=True, null=True) city = models.TextField(max_length=50, blank=True, null=True) country = models.TextField(max_length=50, blank=True, null=True) def __str__(self): return str(self.id) forms.py class CustomUserForm(ModelForm): class Meta: model = User fields = [ 'username', 'id', … -
Connecting Django Dashboard with Chatfuel
I have this project where I have to connect my Django app with a Chatfuel bot. I have my admin panel, so whenever I update a field like complete certain task, I have to notify my client through the chatbot that this field change. I read JSON API docs and I noticed that they have an specific "template" to get data from a backend. What I did is extract all my data from the models through Django Rest Framework and convert it to a JSON. The thing is I don't know how to use this information to work with it in Chatfuel because my JSON hasn't the template that Chatfuel requires. This is my info extracted from the models. This is what Chatfuel needs. -
failed to use virtualenv in pycharm
enter image description here I actually have python file in scripts but I can't import python in script while importing new environment -
How to prefetch multiple fields by the same queryset
I'm trying to do a Prefetch on my Models The Models are like so: Model A ---Field 1 ---Field 2 Model B ---Field RR FK to Model A related_name RR ---Field SS FK to Model A related_name SS I was making a prefetch for my model A and I ended up with something like this B = B.objects.all() A = A.prefetch_related( Prefetch('RR', queryset=B), Prefetch('SS', queryset=B) ) However, this results in 2 queries (one for RR, and one for SS) to the same queryset. Is there any way to avoid this by making RR and SS use the same prefetch? -
Unable to create the django_migrations table (ORA-02000: missing ALWAYS keyword)
I'm starting a project in Django-2.0.1 with a database Oracle 11g, and when I run $python manage.py migrate, I get the error django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (ORA-02000: missing ALWAYS keyword). You can see the full stack below: Traceback (most recent call last): File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/oracle/base.py", line 500, in execute return self.cursor.execute(query, self._param_generator(params)) cx_Oracle.DatabaseError: ORA-02000: missing ALWAYS keyword The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in ensure_schema editor.create_model(self.Migration) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 298, in create_model self.execute(sql, params or None) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 117, in execute cursor.execute(sql, params) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute return super().execute(sql, params) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers return executor(sql, params, many, context) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute return self.cursor.execute(sql) File "/Users/user/anaconda3/lib/python3.6/site-packages/django/db/backends/oracle/base.py", line 500, in execute return self.cursor.execute(query, self._param_generator(params)) django.db.utils.DatabaseError: ORA-02000: missing ALWAYS keyword During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 15, in <module> … -
How do we write child templates that extends more than one parent template in Django?
I've been learning Django through an Udemy course and got through Template Inheritance. From what I understand it works as follows: templates/myapp/parent.html <div class="container"> {% block child_block %} {# delegated to child template #} {% endblock %} </div> templates/myapp/child.html <!DOCTYPE html> {% extends "myapp/parent.html" %} {% block child_block %} <!-- child content --> {% endblock %} We have a parent template parent.html and a child template child.html. The parent template declares a block that it will delegate to the child template. The child template declares the parent it extends and then declares the same block with the content it contains. During page construction, Django will construct the parent template, reach the block, and fill it with the content declared by the child template ---with the stipulation that you don't use blocks with the same name in any given template (to prevent name collision). This pattern works great for use-cases where a parent template may have multiple children and/or multiply nested children. You organize the template code more efficently and in smaller more manageable blocks. If a child were to be repeated N times (usually through a for loop), you delegate a block within the for loop to ensure each iteration … -
Django Internationalization--without gettext
There is a way to make 2 language site by copying the same site, and changing the urls and templates without using gettext and standard internationalization steps. Due to some sorts of errors my mac can't cope with gettext etc. Is there a simple way not to use gettext etc? I am thinking of copying the app and doing 2 sites one for en and one for my language. I would really appreciate it if you have also some videos that show how i can do that. Thank you! -
CreateView + dynamic form display with AJAX
I'm working on a simple django project for expenses management. I got a manage_operations view which is responsible for displaying all Operations and it generates page which looks like this: Clicking on add new operation link results in loading new page with a new Operation form. Below you can find my current code: views.py class OperationCreate(CreateView, OperationMixIn): model = Operation form_class = OperationForm success_url = reverse_lazy('manage_operations') def get_form_kwargs(self): # some irrelevant kwargs updating ... return kwargs def form_valid(self, form): # some irrelevant operations using values given by user in the form ... return super(OperationCreate, self).form_valid(form) models.py class Operation(models.Model): types_tuples = ((-1, 'expense'), (1, 'earning')) def get_category_color(self): return Category.objects.get(pk=self.category.id).color user = models.ForeignKey(User) account = models.ForeignKey(Account) category = models.ForeignKey(Category) date = models.DateField() amount = models.DecimalField(max_digits=10, decimal_places=2) type = models.IntegerField(choices=types_tuples) currency = models.CharField(max_length=3) color = property(get_category_color) forms.py class OperationForm(ModelForm): class Meta: model = Operation fields = ['account', 'type', 'category', 'date', 'amount'] def __init__(self, user, *args, **kwargs): super(OperationForm, self).__init__(*args, **kwargs) self.fields['account'].queryset = Account.objects.filter(user=user) self.fields['category'].queryset = Category.objects.filter(user=user) operation_form.html <form action="" method="POST"> {% csrf_token %} {{ form.as_p }} <input type="submit" value="save" /> </form> What I'm currently trying to achieve is that new Operation form is being displayed as a bootstrap modal on top of my `manage_operations' … -
OSError: mysql_config not found
I tried installing mysqlclient on python today but it gets all messy and gives me this error raise EnvironmentError("%s not found" % (mysql_config.path,)) OSError: mysql_config not found then I tried to edit the mysql.config file by adding #Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto" but still it gives me the same error. I am on mac version 10.6.8. The details of the error are: ****Complete output from command python setup.py egg_info: /bin/sh: mysql_config: command not found Traceback (most recent call last): File "", line 1, in File "/private/var/folders/s4/s4O4m-85EgGDXYYsUzcvNU+++TQ/-Tmp-/pip- build-s7w0agk6/mysqlclient/setup.py", line 17, in metadata, options = get_config() File "/private/var/folders/s4/s4O4m-85EgGDXYYsUzcvNU+++TQ/-Tmp-/pip- build-s7w0agk6/mysqlclient/setup_posix.py", line 44, in get_config libs = mysql_config("libs_r") File "/private/var/folders/s4/s4O4m-85EgGDXYYsUzcvNU+++TQ/-Tmp-/pip- build-s7w0agk6/mysqlclient/setup_posix.py", line 26, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) OSError: mysql_config not found**** I will really appreciate any help. -
can't connect to Selenium server from vagrant machine
i built my first web project on a vagrant machine. I would like to run some browser tests with selenium. i have the tests (and rest of project) on virtual machine. it appears that I can use selenium server standalone to connect to my local machine and run the browsers on the local machine. On the local machine, I run the following: java -jar selenium-server-standalone-3.8.1.jar I get a bunch of successful code including: osjs.AbstractConnector:main: Started ServerConnector@709a8be8{HTTP/1.1,[http/1.1]}{0.0.0.0:4444} Presumably, that is where i can connect from my virtual machine. I then have a small python script: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities driver = webdriver.Remote( command_executor='http://0.0.0.0:4444', desired_capabilities=DesiredCapabilities.CHROME) driver.get("http://www.python.org") I get the following error: urllib.error.URLError: <urlopen error [Errno 111] Connection refused> I can't find much more detail on this process than these steps. If someone could help with this problem, I'd be grateful. -
Redis Server In EC2: Elastic Beanstalk, Django, Django Channels
I would love to have a development AWS environment run completely free, but this means that I must confine all my services into one ec2 instance. Currently, my stack consists of a Django web process running on port 80, a Daphne instance running on port 5000 and a redis server running on a different ec2 instance all together on port 6397. I am in the process of moving the aforementioned redis server into the same ec2 that my Django and Daphne processes run on. I had everything working on two separate ec2 instances, however, when I merged the redis server into the same instance, my web socket urls started to return 404 errors. Does anyone know if this is possible to run all services within the same ec2 as I have described? If so, what could I be doing incorrectly based on my configuration below? My only red flag that I see is in the netstat command results below... It appears that there are many different targets for the redis process being that it is listening on a certain IP and established on a different IP. Let me know if there are other logs that you would like to see. … -
Error with command $python3 manage.py migrate
I'm new to Django and I am running Django inside a virtualenv on MacOS with python 3.6. The command $python3 manage.py migrate but I keep getting an error asking me to install mysqlclient. Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module> import MySQLdb as Database File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module> import _mysql ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libmysqlclient.20.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so Reason: image not found The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute django.setup() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate app_config.import_models() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_import File "<frozen importlib._bootstrap>", line 971, in _find_and_load File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 665, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module> class … -
Django Internationalization---compilemessages error:AttributeError: module 'locale' has no attribute 'normalize'
I am just before finishing line and feel that i don't finish yet! I created and compiled all of the messages in order to have a site with 2 languages and i received this error when running the server: AttributeError: module 'locale' has no attribute 'normalize'. Can someone please help me? Traceback (most recent call last): File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 306, in execute parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False) File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/base.py", line 47, in __init__ super().__init__(**kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1633, in __init__ self._positionals = add_group(_('positional arguments')) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 606, in gettext return dgettext(_current_domain, message) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 570, in dgettext codeset=_localecodesets.get(domain)) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 505, in translation mofiles = find(domain, localedir, languages, all=True) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 477, in find for nelang in _expand_lang(lang): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 206, in _expand_lang loc = locale.normalize(loc) AttributeError: module 'locale' has no attribute 'normalize' Process finished with exit code 1 This is how my locale folder looks like: