Python decouple 模块,config() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用decouple.config()

项目:blog-django    作者:delitamakanda    | 项目源码 | 文件源码
def post_share(request, post_id):
    post = get_object_or_404(Post, id=post_id, status='published')
    sent = False

    if request.method == 'POST':
        form = EmailPostForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            post_url = request.build_absolute_uri(post.get_absolute_url())
            subject = '{} ({}) recommends you reading "{}"'.format(cd['name'], cd['email'], post.title)
            message = 'Read "{}" at {}\n\n{}\'s comments: {}'.format(post.title, post_url, cd['name'], cd['comments'])
            send_mail(subject, message, config('DEFAULT_FROM_EMAIL'), [cd['to']])
            sent = True
    else:
        form = EmailPostForm()
    return render(request, 'blog/post/share.html', {'post': post, 'form': form, 'sent': sent })
项目:python-boleto-cloud    作者:hudsonbrendon    | 项目源码 | 文件源码
def setUp(self):
        self.ticket = Ticket(config('TOKEN'))
项目:python-boleto-cloud    作者:hudsonbrendon    | 项目源码 | 文件源码
def test_token(self):
        self.assertEqual(self.ticket._token, config('TOKEN'))
项目:python-boleto-cloud    作者:hudsonbrendon    | 项目源码 | 文件源码
def test_authorization(self):
        self.assertEqual(self.ticket._authorization.username, config('TOKEN'))
        self.assertEqual(self.ticket._authorization.password, 'token')
项目:verse    作者:pawelad    | 项目源码 | 文件源码
def get_github_api_client():
    """
    Helper function for initializing GitHub API client

    :return: github3.Github
    """
    token = config('GITHUB_TOKEN', default=None)
    return GitHub(token=token)
项目:is-service-up    作者:marcopaz    | 项目源码 | 文件源码
def __init__(self, cachet_url="", cachet_token="",
                 cachet_components=None):
        self.cachet_url = cachet_url or config('CACHET_URL', default=None)
        self.cachet_token = (cachet_token or
                             config('CACHET_TOKEN', default=None))
        self.cachet_components = (cachet_components or
                                  config('CACHET_COMPONENTS', default=None,
                                         cast=self._components_to_dict))
项目:is-service-up    作者:marcopaz    | 项目源码 | 文件源码
def __init__(self):
        # Will check if the Weblate website is OK.
        self.check_http = config('WEBLATE_CHECK_HTTP', default=True, cast=bool)
        # Will check if the Weblate JSON API is OK.
        self.check_json = config('WEBLATE_CHECK_JSON', default=True, cast=bool)
        # If you need to monitor multiple Weblate instances and need each one
        # to have a different behaviour: extend this class, override the
        # __init__ function, call super, and then override these properties.
项目:push-dev-dashboard    作者:mozilla-services    | 项目源码 | 文件源码
def setUpClass(cls):
        super(SeleniumTests, cls).setUpClass()
        cls.firefox_profile = FirefoxProfile()
        server_url = config('TEST_PUSH_SERVER_URL', default=False)
        if server_url:
            cls.firefox_profile.set_preference('dom.push.serverURL',
                                               server_url)
        cls.selenium = WebDriver(firefox_profile=cls.firefox_profile)
项目:push-dev-dashboard    作者:mozilla-services    | 项目源码 | 文件源码
def setUp(self):
        self.site = config('TESTING_SITE', 'http://127.0.0.1:8000')
        self.email = config('TESTING_FXA_ACCOUNT_EMAIL', None)
        self.password = config('TESTING_FXA_ACCOUNT_PASSWORD', None)
        self.signing_key, self.verifying_key, self.vapid_key = gen_keys()
项目:blog-django    作者:delitamakanda    | 项目源码 | 文件源码
def contact_us_view(request):
    form_class = ContactForm

    if request.method == 'POST':
        form = form_class(data=request.POST)

        if form.is_valid():
            contact_name = request.POST.get('contact_name', '')
            contact_email = request.POST.get('contact_email', '')
            form_content = request.POST.get('content', '')
            template = get_template('blog/contacts/contact_template.txt')
            context = Context({
                'contact_name': contact_name,
                'contact_email': contact_email,
                'form_content': form_content
                })
            content = template.render(context)

            email = EmailMessage(
                "Nouveau message du Blog",
                content,
                "Votre site"+ '',
                [config('DEFAULT_FROM_EMAIL')],
                headers = { 'Reply-To': contact_email }
                )
            email.send()
            messages.success(request, 'Thank you for your email my friend !')
            return redirect('/')

    return render(request, 'blog/contacts/contact_form.html', {'form': form_class})
项目:blog-django    作者:delitamakanda    | 项目源码 | 文件源码
def api_post_detail(request, id):
    try:
        post = Post.objects.get(id=id)
    except Post.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = PostSerializer(post, context={'request': request})
        return Response(serializer.data)


#@api_view(['POST', 'GET'])
#def contact_mail_ws(request):
    #if request.method == 'POST':
        #contact = ContactMailSerializer(data=request.data)
        #if contact.is_valid():
            #form_name = contact.data['name']
            #form_phone = contact.data['phone']
            #form_email = contact.data['email']
            #form_message = contact.data['message'] + "email: " + form_email

            #send_mail("New contact form submission",
                #form_message,
                #form_email,
                #[config('DEFAULT_FROM_EMAIL')],
                #fail_silently=False
            #)

            #return Response(contact.data, status=status.HTTP_201_CREATED)
    #return Response({"success": False, 'error-code': 'invalid-data'})
项目:searchads-api    作者:BendingSpoons    | 项目源码 | 文件源码
def api_call(endpoint, headers={}, json_data={}, method=requests.get,
             api_version='v1', limit=1000, offset=0, org_id=None,
             verbose=False):
    endpoint = "{}/{}".format(api_version, endpoint)
    # print("Endpoint:", endpoint)
    # print("Data:", json_data)

    temp_pem = NamedTemporaryFile(suffix='.pem')
    temp_key = NamedTemporaryFile(suffix='.key')

    pem_env_var = config('SEARCH-ADS-PEM')
    key_env_var = config('SEARCH-ADS-KEY')

    try:
        if pem_env_var.endswith('.pem'):  # env is the name of file
            call_kwargs = {
                "cert": (
                    pem_env_var,
                    key_env_var
                ),
                "headers": headers,
            }
        else:   # env var is the key explicit
            pem_lines = pem_env_var.split("\\n")
            temp_pem.writelines(["%s\n" % item for item in pem_lines])
            temp_pem.flush()  # ensure all data written

            key_lines = key_env_var.split("\\n")
            temp_key.writelines(["%s\n" % item for item in key_lines])
            temp_key.flush()  # ensure all data written

            call_kwargs = {
                "cert": (
                    temp_pem.name,
                    temp_key.name
                ),
                "headers": headers,
            }
        if json_data:
            call_kwargs['json'] = json_data
        if org_id:
            call_kwargs['headers']["Authorization"] = "orgId={org_id}".format(
                org_id=org_id)
        req = method(
            "https://api.searchads.apple.com/api/{endpoint}".format(
                endpoint=endpoint),
            **call_kwargs
        )
    finally:
        # Automatically cleans up the file
        temp_pem.close()
        temp_key.close()

    if verbose:
        print(req.text)
    return req.json()