Python django.conf.settings 模块,HOSTNAME 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用django.conf.settings.HOSTNAME

项目:home-data-api    作者:data-skeptic    | 项目源码 | 文件源码
def create_profile(sender, instance, **kwargs):
    new_account = False
    if kwargs['created']:
        profile = Profile.objects.create(user=instance)
        new_account = True
    else:
        profile = Profile.objects.filter(user=instance)
        if len(profile) == 0:
            profile = Profile.objects.create(user=instance)
            new_account = True

    if new_account:
        profile.update_code()
        link_text = settings.HOSTNAME + profile.get_confirmation_link()
        if not settings.TESTING:
            send_signup_email(instance.email, link_text)
项目:mercure    作者:synhack    | 项目源码 | 文件源码
def build(self, tracker):
        """
            Use for build file's attachment if it's buildable
            :param tracker: Allow to know if user open/execute the attachment
            :return binary: Build of the file
        """
        if not self.buildable:
            return self.file

        with tempfile.TemporaryDirectory() as path:
            zipfile.ZipFile(self.file.path).extractall(path)
            builder_path = os.path.join(path, 'generator.sh')
            if not os.path.exists(builder_path):
                raise SuspiciousOperation('Unable to find builder script')

            # get values
            tracker_id = str(tracker.pk)
            target = tracker.target
            hostname = settings.HOSTNAME[:-1] if \
                settings.HOSTNAME.endswith('/') else settings.HOSTNAME
            tracker_url = hostname + reverse('tracker_img', args=(tracker_id,))

            # make env vars
            env = os.environ.copy()
            env.update({
                'TRACKER_URL': tracker_url,
                'TARGET_EMAIL': target.email,
                'TARGET_FIRST_NAME': target.first_name,
                'TARGET_LAST_NAME': target.last_name,
            })

            # TODO: Find a way to handle this RCE ;)
            cmd = ['sh', builder_path]
            out_b64 = check_output(cmd, cwd=path, env=env).decode().strip()
            return BytesIO(b64decode(out_b64))
项目:linty    作者:ZeroCater    | 项目源码 | 文件源码
def publish_status(self, auth, state, description):
        hostname = settings.HOSTNAME
        build_url = reverse('build_detail', kwargs={'pk': self.id})
        details_url = 'https://{0}{1}'.format(hostname, build_url)
        data = {
            'state': state,
            'description': description,
            'target_url': details_url,
            'context': 'linty'
        }
        requests.post(self.status_url, json=data, auth=auth)
项目:EasterEggs    作者:nst    | 项目源码 | 文件源码
def image_url(self):
        if not self.image:
            return None
        return settings.HOSTNAME + self.image.url
项目:django_auto_healthchecks    作者:cronitorio    | 项目源码 | 文件源码
def _get_hostname(self):
        """ Try to determine the hostname to use when making the healthcheck request
        :return: string
        :raises HealthcheckError """

        # First look in settings.HEALTHCHECKS['HOSTNAME']
        try:
            if _get_setting('HOSTNAME'):
                return _get_setting('HOSTNAME')
        except HealthcheckError:
            pass

        # Then try settings.HOSTNAME, if it exists
        try:
            if hasattr(settings, 'HOSTNAME') and len(settings.HOSTNAME):
                return settings.HOSTNAME
        except (AttributeError, TypeError):
            pass

        # Finally, pop the first value from settings.ALLOWED_HOSTS
        try:
            if hasattr(settings, 'ALLOWED_HOSTS') and len(settings.ALLOWED_HOSTS):
                return settings.ALLOWED_HOSTS[0]
        except (AttributeError, TypeError, KeyError):
            pass

        raise HealthcheckError(
            'Error: Could not determine hostname from settings.HEALTHCHECKS["HOSTNAME"], '
            'settings.HOSTNAME or settings.ALLOWED_HOSTS'
        )