Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to build an image from an str containing the binary data?
I have a byte string, and trying to convert it into a file but I keep getting an error: OS Error cannot identify image file <_io.BytesIO object at 0x03BBD330> The code that I've implemented is below: def test_view(request): with open("test_json.json") as imageFile: b=bytearray(json.load(imageFile)["IMAGE_DATA"], 'utf8') print(b) image = Image.open(io.BytesIO(b)) response = HttpResponse(content_type="image/jpeg") image.save(response, "JPEG") return response The byte string is read from a json file, it looks like this, but it is much longer, I've just copied some characters. "b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x01\\x01\\x01\\x00`\\x00`\\x00\\x00\\xff\\xdb\\x00C\\x00\\x05\\x04\\x04\\x04\\x04\\x03\\x05\\x04\\x04\\x04\\x06\\x05\\x05\\x06\\x08\\r\\x08\\x08\\x07\\x07\\x08\\x10\\x0b\\x0c\\t\\r\\x13\\x10\\x14\\x13\\x12\\x10\\x12\\x12\\x14\\x17\\x1d\\x19\\x14\\x16\\x1c\\x16\\x12\\x12\\x1a#\\x1a\\x1c\\x1e\\x1f!!!\\x14\\x19$\\'$ &\\x1d ! \\xff\\xdb\\x00C\\x01\\x05\\x06\\x06\\x08\\x07\\x08\\x0f\\x08\\x08\\x0f \\x15\\x12\\x15 \\xff\\xc0\\x00\\x11\\x08\\x01&\\x02q\\x03\\x01\"\\x00\\x02\\x11\\x01\\x03\\x11\\x01\\xff\\xc4\\x00\\x1f\\x00\\x00\\x01\\x05\\x01\\x01\\x01\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\xff\\xc4\\x00\\xb5\\x10\\x00\\x02\\x01\\x03\\x03\\x02\\x04\\x03\\x05\\x05\\x04\\x04\\x00\\x00\\x01}\\x01\\x02\\x03\\x00\\x04\\x11\\x05\\x12!1A\\x06\\x13Qa\\x07\"q\\x142\\x81\\x91\\xa1\\x08#B\\xb1\\xc1\\x15R\\xd1\\xf0$3br\\x82\\t\\n\\x16\\x17\\x18\\x19\\x1a%&\\'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99\\x9a\\xa2\\xa3\\xa4\\xa5\\xa6\\xa7\\xa8\\xa9\\xaa\\xb2\\xb3\\xb4\\xb5\\xb6\\xb7\\xb8\\xb9\\xba\\xc2\\xc3\\xc4\\xc5\\xc6\\xc7\\xc8\\xc9\\xca\\xd2\\xd3\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xe1\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\\xe9\\xea\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf7\\xf8\\xf9\\xfa\\xff\\xc4\\x00\\x1f\\x01\\x00\\x03\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\xff\\xc4\\x00\\xb5\\x11\\x00\\x02\\x01\\x02\\x04\\x04\\x03\\x04\\x07\\x05\\x04\\x04\\x00\\x01\\x02w\\x00\\x01\\x02\\x03\\x11\\x04\\x05!1\\x06\\x12AQ\\x07aq\\x13\"2\\x81\\x08\\x14B\\x91\\xa1\\xb1\\xc1\\t#3R\\xf0\\x15br\\xd1\\n\\x16$4\\xe1%\\xf1\\x17\\x18\\x19\\x1a&\\'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\\x82\\x83\\x84\\x85\\x86\\x87\\x88\\x89\\x8a\\x92\\x93\\x94\\x95\\x96\\x97\\x98\\x99'" -
Django model with dynamic db tables
I am using Django to interface with another (JAVA) application that based on some events generates at runtime tables in the db with the same model. So I don't have a direct control over the DB. For example: Sensor1 id | value | time 1 10 2018-10-11 Sensor2 id | value | time 1 12 2018-10-11 Currently, my Django model is looking something like this: Sensor(models.Model): value = models.IntegerField() time = models.DatetimeField() class Meta: managed = False db_table = "Sensor1" Do you have any clue if I can set the model somehow to be able to gain the data from a different table based on the query? Ideally, something that would allow me to get the data in the fashion of: config_tables=['Sensor1','Sensor2'] for table in config_tables: data = Sensor.objects.table(table).objects.all() Other option might be also to have a SQL query that executes on different tables, so perhaps something like: SELECT * FROM %s; -
Django reverse going for the wrong view function
I have the following url patterns defined in the urls.py urlpatterns = [ path('', views.index, name='index'), path('start', views.start, name='start'), path('<slug:id>' , views.person, name="person"), path('family/<slug:id>', views.family, name="family") ] And the first 3 works just fine, for example if I call this link: <a href="{% url 'pops:person' id=my_id %}"> Everything works fine and I go to the persons page, The other link such as start and index also works fine. But somehow if I do this link: <a href="{% url 'pops:family' id=my_id %}"> Everything fails and throws a reverse not found error: Reverse for 'index' with keyword arguments '{'id': 'BLAHBLAH'}' not found. The problem is, I'm not even going for the index, Why is it reversing for index when it should be reversing for family? As a result, it's not even hitting the function defined in the views at all. -
Django user with is_staff permission can log with any password
I am using Django 2.x.x I recently found out that a Django user with "is_staff" permission can log in the dashboard with any random string. This happens only for the admin dashboard and I have proper authentication backend setup for my actual django application. Any idea why this would be the case? -
Problem making a GET on my site when it is entered via www (react + django)
I have a django application that uses React on some of its pages (Only one server in django that have a react page). In my pages in React, I make HTTP requests to django api using Django Rest Framework. This application is already running, and in it I noticed a problem. If I enter the site without "www", log in normally and access the pages via react, everything works perfectly. However, when I use "www" to access the site, it first makes me redo the login (it does not save that I was already logged in) and also, when accessing the pages in react, the GET request gives the 403 error, which Credentials were not provided, however, without the "www" it works fine. DRF data in settings.py: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication', ), 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated', ], 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',) } I really don't know if it is a DRF problem, something that was missing from the request, or some HTTPS redirect problem. Would anyone have any idea what it might be? Thank you! -
How to Use ObjectURL with Django?
I am making a simple file uploader. As I learn more about file uploading process, somebody recommended me to skip FileReader and just use Blob. I want to try this. As far as I understand, the uploaded file is stored in a browser and does not reach Django server. However, because the uploaded picture src URL technically has a unmapped URL with urls.py, it will not show up on a web page. What to do? -
For loop inside an email html template in Django
I'm using Django and this problem has been killing me. Basically I need to send a dict contains an item's property in an email. The dict has various keys and I don't know all the keys present in one dict before hand (as the content is Json parsed from another source). An example dict: {"length":123, "width":72, "property1":"dummy", "propertyX":"dummy"} What I need to is to print each key of the dict in one line in my email. I'm using EmailMultiAltinative now but I'm now sure how to format my email.txt and email.html files in the template. If it's just a variable i can just substitute where I want to put it with {{var}} and pass var in context, but now since I would need some kind of loop to iterate through all the keys I have no idea what I should do. Any advice would be appreciated. -
Local setting not found for host name
Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line utility.execute() File "/Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute settings.INSTALLED_APPS File "/Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ self._setup(name) File "/Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup self._wrapped = Settings(settings_module) File "/Users/omairbukhari/env_justads/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/omairbukhari/justads/backend/AdEnhancers/settings.py", line 368, in <module> raise Exception("Local settings not found for host %s" % hostname) Exception: Local settings not found for host unknown Local host is not working, It was working perfectly fine I dont know what heppend, I was working on it just a few minutes ago, here is the traceback. -
django_heroku packaged isn't working with Django app
I need to configure my Django app to pull the heroku config vars (The DATABASE_URL and SECRET_KEY) to get the database to work with it. I look at the docs for django_heroku which said to put this at the bottom of the settings.py file after installing the package: import django_heroku django_heroku.settings(locals()) I entered all that in and ran the server and got this error message: I unfortunately can't understand this error message enough to get the relevant information to fix this problem. Would you know how I can fix this so I can't get my Django app to work with the database in Heroku? Any assistance with this problem will be much appreciated! -
Q object django returns empty QuerySet when AND together
In the django shell, when I filter individual Q object, it returns correct QuerySet. But when the same Q objects are AND together, it returns an empty QuerySet. File.objects.filter(Q(relatedjira__content__icontains='1112')) <QuerySet [<File: abc.txt>]> File.objects.filter(Q(relatedjira__content__icontains='5368')) <QuerySet [<File: abc.txt>]> But when I combine the Q objects with AND, it returns empty set: File.objects.filter(Q(relatedjira__content__icontains='1112') & Q(relatedjira__content__icontains='5368')) <QuerySet[]> -
django-models which field for asteriks *?
I'm setting up a database in Django. Which is the correct field type for asteriks * in models.py? I have tried TextField, IntegerField and Charfield. class Task(models.Model): class Meta: verbose_name_plural = 'Task' save_date = models.DateTimeField(default=timezone.now()) hour_cr = models.TextField(default=*, validators=[MaxValueValidator(24), MinValueValidator(0)]) minute_cr = models.TextField(default=*, validators=[MaxValueValidator(59), MinValueValidator(0)]) day_of_the_month_cr = models.TextField(default=*, validators=[MaxValueValidator(31), MinValueValidator(0)]) month_cr = models.TextField(default=*, validators=[MaxValueValidator(12), MinValueValidator(1)]) day_of_week_cr = models.TextField(default=*, validators=[MaxValueValidator(7), MinValueValidator(1)]) name_task = models.TextField(max_length=25) user = models.ForeignKey(User, on_delete=models.CASCADE) -
Django Session not working between multiple views
I have a login view which renders a login page for the user to fill. Once the user submits the login page, a post call is made to another view named home. This home view verifies the user credentials and if successful redirects to another view that renders a new html file. ISSUE:- I setup a session field in the home view and then from there when the flow gets redirected to the other view, the session field becomes invalid. I cannot give the entire code due to company policy, but I am giving as much as is needed to explain my question. N.B:- When the Index.html is loaded, the post transaction is through AJAX/jquery from the Index.html file and on success the same index.html file accesses the view XYZ using window.location.href('/XYZ'); def index(request): return HttpResponseRedirect(reverse('login')) def login( request ): return render_to_response('Index.html') def home( request ): login( user ); request.session['userName'] = username; return HttpResponse( "SUCCESS" ) def XYZ( request ): print( request.session['userName']) return HttpResponse( "FAILED" ) -
Django: Many2Many Relationship During Pre_Save Signal?
Let's assume we have the following class: Class 'Config' class Config(models.Model): name = models.CharField(max_length=40, editable=True, blank=False, null=False) nodes = models.ManyToManyField(HierarchyNode_MPTT) element = models.ForeignKey(ForecastConfigurationLayout, on_delete=models.PROTECT, default=None) The nodes attribute represents an M:N relationship. I want to default the elements attribute based on the combination of nodes. So, during the save process (ideally pre_save) I need to pass all the nodes to a class/method that returns a uuid for element. So, I go to the admin application, create an object of type Config, select my nodes on the screen and hit save. Now, the system should call a class/method, pass the nodes and update element with the uuid. This doesn't work, because of the M:N relationship in the mapping table between Class and Nodes does not yet have the correct entries (because it's pre_save). I would like to avoid post_save because then the nodes attribute needs to allow Null values. Any ideas are much appreciated. Thanks, Sebastian -
How to store tags with serializer when saving an article in django?
I want to implement tagging functionality whereby tags are created with an article. I have set up two models i.e Article and Tag. On the Article model, I have defined a tags field (ManyToMany Field ) that references the Tag. The code I have right now creates the article with the tags just fine. I feel like it can be improved though. Someone told me I am hard-coding a lot of stuff(repeating myself). For example, he pointed out I should not be defining a custom method for creating tags. So, now I am thinking there is maybe a way of calling the TagSerializer inside the post method to save the tags with the article. I am really not sure how to go about this though. Is there anything I can do to improve the tag code by utilizing the inbuilt Django principles more? (Specifically the part of saving tags). Models.py from django.db import models from django.utils import timezone from authors.apps.authentication.models import User from .utils import get_unique_slug class Tag(models.Model): """ Model for Tag """ tag = models.CharField(max_length=30, unique=True) slug = models.SlugField(max_length=100, unique=True) author = models.ForeignKey('authentication.User', on_delete=models.CASCADE) def __str__(self): return self.tag class Article(models.Model): """ Model for Article """ author = models.ForeignKey(User, on_delete=models.CASCADE) … -
Python 3.2.2 [2018]: Cannot install Pip 7.1.2 (No matching distribution found for 7.1.2)
I'm sure there have been others who had this same problem, but those kind of posts of been difficult to track down or don't help resolve my issue. I'm trying to get an old Django project from 2015 up and running but it keep encountering runtime errors on the newer version of Django and Python. This project was originally built in Django 1.6.5 using Python 3.2.2, so I'm trying to recreate that dev environment so I can see the project working and hope to bring it up to standard with at least Python 3.4 and Django 1.11. I have Python 3.2.2 installed, but I've run into problems getting Pip to install. I'm aware that Pip wasn't bundled with Python until 3.3, so I'm trying to install it myself using get-pip from https://bootstrap.pypa.io/3.2/get-pip.py. When I execute this script it returns an error. PS F:\temp> python get-pip.py 7.1.2 Collecting 7.1.2 Could not find a version that satisfies the requirement pip<8 (from versions: ) No matching distribution found for pip 7.1.2 I found this post (Install pip<v8 in python3.2) that led me to bootstrap.pypa.io, but the solutions there isn't helping. Am I installing pip 7.1.2 correctly, or does it just flat out not … -
Constructing a dynamic query using user input in Django
I have a big model which stores 10 text based values, and 10 numerical values. Something like this: class Dataset(models.Model): text_field_1 = models.CharField(max_length=255) . . . text_field_10 = models.CharField(max_length=255) number_field_1 = models.IntegerField() . . . number_field_10 = models.IntegerField() Now, what I want to do is give users to a way to filter, and order datasets using these fields, by passing in an object to a view. Hopefully, the example below shows what I want to do: obj = { "filters" : [ "text_field_1='vaccines'", "number_field_5__gte=1000", ], "order_by" : "text_field_3, -number_field_7", "excludes" : [], } generate_query(obj) # Dataset.objects.filter(text_field_1='vaccines', number_field_5__gte=1000).order_by('text_field_3', '-number_field_7') So by calling the generate_query(obj), we get the queryset in the comment. Now, due to the nature of this model, its impossible for me to do this manually, by accounting for every possible combination of filters, orders, and excludes. What is the best, and safest way to implement this? The only thing that comes to my mind is creating a big string, and then using exec or eval to execute the string. -
Django form validation through models.py
I am trying to make the action of send an automatic email after the admin hits the "save" button after create an object in a particular Model. One way to do that is to validate the form in the models.py file. The question is how can I do that? I have tried that in views.py as shown below: def admin_email_sender(request): if request.method == 'POST': form = FaturaForm(request.POST) if form.is_valid(): subject = 'Notificação de fatura' from_email = settings.DEFAULT_FROM_EMAIL to_email = [str(form.cleaned_data['cliente'].email)] signup_message = 'Olá, ' + str(form.cleaned_data['cliente']) + '\n' + \ 'Você possui uma fatura para pagar até o dia ' + \ str(form.cleaned_data['dia']) + ' de ' + str(form.cleaned_data['mes']) + ' de ' + str(form.cleaned_data['ano']) send_mail(subject, signup_message, from_email, to_email, fail_silently=False) Maybe it is possible to do it with other ways. Thanks in advance. -
Reverse for 'register' not found. 'register' is not a valid view function or pattern name
I'm trying to make a simple app that uses the django built-in User model. I have created a registration page, but when I run the server, I get this error at the index page. Here's the code I'm using: Registration.html <!DOCTYPE html> {% extends "basic/base.html" %} {% block title_block %} <title>Registration</title> {% endblock title_block %} {% block body_block %} <div class="jumbotron"> {% if registered %} <h1>Thank you for registering</h1> {% else %} <h1>Register here!</h1> <h3>Fill out the form: </h3> <form enctype="multipart/form-data" method="post"> {% csrf_token %} {{userForm.as_p}} {{profileForm.as_p}} <input type="submit" value="Register" name=""> </form> {% endif %} </div> {% endblock body_block %} Views.py for the 'register' method def register(request): registered = False if(request.method == 'POST'): userForm = forms.UserForm(data=request.POST) profileForm = forms.UserProfileInfoForm(data=request.POST) if((userForm.is_valid()) and (profileForm.id_valid())): user = userForm.save() user.set_password(user.password) user.save() profile = profileForm.save(commit=False) profile.user = user if('profileImage' in request.FILES): profile.profileImage = request.FILES['profileImage'] profile.save() registered = True else: print(userForm.errors, profileForm.errors) else: userForm = forms.UserForm() profileForm = forms.UserProfileInfoForm() return render(request, 'basic/registration.html', {'userForm':userForm, 'profileForm':profileForm, 'registered':registered}) And the link to the page in base.html <a class="nav-link" href="{% url 'basic:register' %}">Register</a> What can cause the error here? -
populate dinamic list queryset with ausent values and merge it
I'm trying create a list with 12 months and yours respect value, but if month/value ausent I need create a default "0" and merged with dinamyc data. from collections import OrderedDict _qs = CheckOut.objects.filter(date_service__year = datetime.datetime.now().year).values_list('date_service__month').\ annotate(total=Sum('checkoutitem__total_value')).order_by('date_service__month') dt = OrderedDict(_qs) # Wrap queryset with an OrderedDict months = list(dt.keys()) valore = list(dt.values()) extra_context['profit'] = [months, valore] And the result in template django: [[9, 10, 11], [Decimal('800.00'), Decimal('300.00'), Decimal('100.00')]] So, I need create the months: 1,2,3,4,5,6,7,8,12 and create the values (if not exists in queryset, default "0". And keep the Order. -
For django testing, how do I use keepdb with mariadb
I have a database with a lot of nonmanaged tables which I'm using for a django app. For testing I'm wanting to use the --keepdb option so that I don't have to repopulate these tables every time. I'm using MariaDB for my database. If I don't use the keepdb option everything works fine, the test database gets created and destroyed properly. But when I try to run the test keeping the database: $ python manage.py test --keepdb I get the following error: Using existing test database for alias 'default'... Got an error creating the test database: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE DATABASE IF NOT EXISTS test_livedb ;\n SET sql_note' at line 2") I assume that this is an issue with a different syntax between MariaDB and MySQL. Is there anyway to get the keepdb option to work with MariaDB? thanks very much! -
"Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted."
I can not find where I'm going wrong, I'm using the documentation for this. I'm already using PostgreSQL. Version of Django = 2.1.2, using in a virtual environment linux. >>> questao = Questoes.objects.get(pk=7) >>> questao.titulo '133 (Enem 2012 - Segundo Dia)' >>> Questoes.objects.all() <QuerySet [<Questoes: teste aa bb cc>, <Questoes: 133 (Enem 2012 - Segundo Dia)>]> >>> Questoes.objects.filter(titulo__trigram_similar='enen') Traceback (most recent call last): File "<console>", line 1, in <module> File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/query.py", line 844, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/query.py", line 862, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1263, in add_q clause, _ = self._add_q(q_object, self.used_aliases) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1287, in _add_q split_subq=split_subq, File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1225, in build_filter condition = self.build_lookup(lookups, col, value) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1090, in build_lookup lhs = self.try_transform(lhs, lookup_name) File "/mnt/sda1/Development/Projetos/vest_container/env/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1126, in try_transform (name, lhs.output_field.__class__.__name__)) django.core.exceptions.FieldError: Unsupported lookup 'trigram_similar' for CharField or join on the field not permitted. project/settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'vestdb', 'USER': '', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', } } models.py from django.db import models from django.urls import reverse from django.utils import timezone from django_extensions.db.fields import AutoSlugField class Questoes(models.Model): #.... titulo = models.CharField(max_length=100, … -
Is it difficult to implement machine learning models on mobile applications using react-native?
And how is it differs from implementing ML models on web applications using Django? Actually, I've been working on an ML project that learns the behaviour of a person from his online activity. I want to deploy the ML model into a web or mobile application. My preferred list is a web application using Django and another one is a mobile application using React-Native. The application will have lots of functionalities based on the learning data. Now, I want to know which one has what kind of difficulties. -
How to gitignore particular files
I am trying to add a few files to .gitignore, but not having luck: # -- in my .gitignore file -- # other items settings_staging.py settings_production.py And to test it I'm doing: $ git check-ignore settings_staging.py I know my .gitignore is working and including some files, such as the __pycache__ files, but how do I get it to ignore particular files I specify? -
Using DjangoFilterConnectionField with custom Connection in graphene_django
I'm trying to use something similar to this: class User(DjangoObjectType): class Meta: model = auth_models.User filter_fields = ('email', ) interfaces = (Node, ) connection = UserConnection class UserConnection(Connection): extra = graphene.String() class Meta: node = User class Query(graphene.ObjectType): users_connection = DjangoFilterConnectionField( User, where=UserWhereInput() ) From my understanding, User node needs to be passed UserConnection on it's meta, and UserConnection needs to be passed User on it's meta. However, it creates a cross reference. Any help? -
Trouble accessing Heroku's config vars with os.environ in Django/Python
I'm hosting a Django app on Heroku and I do not want my database credentials in the settings.py file to be visible in GitHub. Rather, I want them to be accessed in Heroku's config vars. Heroku's docs says it's possible to access the config vars in Python code like this: from boto.s3.connection import S3Connection s3 = S3Connection(os.environ['S3_KEY'], os.environ['S3_SECRET']) So I set the relevant config vars like this: heroku config:set PASSWORD=madeuppassword And I tried to access the config vars in the source code like is says like this: DATABASES = { 'default': { 'ENGINE': os.environ['ENGINE'], 'NAME': os.environ['NAME'], 'USER': os.environ['USER'], 'PORT': os.environ['PORT'], 'PASSWORD': os.environ['PASSWORD'], 'HOST': os.environ['HOST'] } } However when running the server I get this error in my command prompt: raise KeyError(key) from None KeyError: 'Engine' To the best of my knowledge I set and accessed Heroku's config vars as it's demonstrated in their docs but I keep getting this error. What am I possibly doing wrong that it keeps bringing up this error? Any help is appreciated!