django-settings

How to set environment variables in heroku-django project?

旧巷老猫 提交于 2020-01-13 05:54:14
问题 I have this code in my settings.py.. EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') I tried setting environment variable using this in heroku bash export EMAIL_HOST_USER=xxx and also heroku config:set EMAIL_HOST_USER=xxx None of the both method worked for me. How can i set environment variable in heroku? 回答1: okk.. found the answer!! instead of heroku config:set EMAIL_HOST_USER=xxx writing heroku

How to set environment variables in heroku-django project?

你。 提交于 2020-01-13 05:54:09
问题 I have this code in my settings.py.. EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') I tried setting environment variable using this in heroku bash export EMAIL_HOST_USER=xxx and also heroku config:set EMAIL_HOST_USER=xxx None of the both method worked for me. How can i set environment variable in heroku? 回答1: okk.. found the answer!! instead of heroku config:set EMAIL_HOST_USER=xxx writing heroku

How to set multiple settings.py for sites framework django?

旧时模样 提交于 2020-01-07 03:00:36
问题 Am trying to set up multiple website with same base. While browsing, came to know Django has Sites framework which I could use. I didnt get how to set multiple settings.py file with site id. Any ideas anyone? Thanks in advance :) 回答1: you can have multiple setting file for example develop.py and production.py steps 1. create a settings folder inside the project 2. Add all of the settings file to that folder 3 while running server ./manage.py runserver --settings=project_name.settings.required

Calling another serializer from the Serializer messes up URI

百般思念 提交于 2020-01-05 09:03:16
问题 I'm in the debugging mode and I want to set default ImageField to return full URL localhost:8000/path . Here is current JSON data ... "img": "http://localhost:8000/media/outfits/1/4.png", "tagged_clothes": [ { "cloth_image": "/media/clothes/1/7.png", <- This happens when I use settings.py debugging file "id": 6, "b_clothtype": "ETC", settings.py MEDIA_URL = '/media/' # if I change this variable as 'localhost:8000/media/', # JSON returns correct URLs but I couldn't see the image. MEDIA_ROOT =

AttributeError: 'module' object has no attribute 'setup'; django setup working in one project but not other

自闭症网瘾萝莉.ら 提交于 2020-01-03 03:32:16
问题 #!/usr/bin/env python # coding: utf-8 import os, sys, subprocess, time, re, ast os.environ.setdefault("DJANGO_SETTINGS_MODULE", "webapi.server.project.settings") import django django.setup() from django.apps import apps try: cchilders: ./write_creation_tests.py Traceback (most recent call last): File "./write_creation_tests.py", line 17, in <module> django.setup() AttributeError: 'module' object has no attribute 'setup if I remove the setup attempt I can't import apps: #!/usr/bin/env python #

Django: Obtaining the absolute URL without access to a request object

折月煮酒 提交于 2020-01-01 01:31:10
问题 I have a model like the one below. When an instance is created, I want to send out an e-mail to an interested party: class TrainStop(models.Model): name = models.CharField(max_length=32) notify_email = models.EmailField(null=True, blank=True) def new_stop_created(sender, instance, created, *args, **kwargs): # Only for new stops if not created or instance.id is None: return # Send the status link if instance.notify_email: send_mail( subject='Stop submitted: %s' % instance.name, message='Check

Get absolute path of django app

给你一囗甜甜゛ 提交于 2019-12-31 12:54:52
问题 I am writing a unit test that needs to access an image file that I put in "fixtures" directory right under my django app directory. I want to open up this image file in my test using relative path, which would require me to get the absolute path of the django app. Is there a way to get the absolute path of the django app? 回答1: Python modules (including Django apps) have a __file__ attribute that tells you the location of their __init__.py file on the filesystem, so import appname pth = os

Get absolute path of django app

十年热恋 提交于 2019-12-31 12:54:33
问题 I am writing a unit test that needs to access an image file that I put in "fixtures" directory right under my django app directory. I want to open up this image file in my test using relative path, which would require me to get the absolute path of the django app. Is there a way to get the absolute path of the django app? 回答1: Python modules (including Django apps) have a __file__ attribute that tells you the location of their __init__.py file on the filesystem, so import appname pth = os

how can I check database connection to mysql in django

青春壹個敷衍的年華 提交于 2019-12-28 13:22:14
问题 how can I do it? I thought, I can read something from database, but it looks too much, is there something like?: settings.DATABASES['default'].check_connection() 回答1: All you need to do is start a application and if its not connected it will fail. Other way you can try is on shell try following - from django.db import connections from django.db.utils import OperationalError db_conn = connections['default'] try: c = db_conn.cursor() except OperationalError: connected = False else: connected =

django - MySQL strict mode with database url in settings

家住魔仙堡 提交于 2019-12-25 08:50:11
问题 I'm using a database URL string in my settings like: DATABASES = { 'default': "mysql://root:@localhost:3306/mydb" } When I migrate I get this warning: MySQL Strict Mode is not set for database connection 'default' Now my question: How can I combine the two things? I cannot use the "regular" way to set the database settings with a dictionary because my database url comes from an environment variable. Thx in advance! 回答1: You could update your settings afterwards: DATABASES['default']['OPTIONS'