当前位置: 首页>>代码示例>>Python>>正文


Python default_storage.url方法代码示例

本文整理汇总了Python中django.core.files.storage.default_storage.url方法的典型用法代码示例。如果您正苦于以下问题:Python default_storage.url方法的具体用法?Python default_storage.url怎么用?Python default_storage.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.files.storage.default_storage的用法示例。


在下文中一共展示了default_storage.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_render

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_render(self):
        w = widgets.AdminFileWidget()
        self.assertHTMLEqual(
            w.render('test', self.album.cover_art),
            '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/'
            r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> '
            '<span class="clearable-file-input">'
            '<input type="checkbox" name="test-clear" id="test-clear_id"> '
            '<label for="test-clear_id">Clear</label></span><br>'
            'Change: <input type="file" name="test"></p>' % {
                'STORAGE_URL': default_storage.url(''),
            },
        )
        self.assertHTMLEqual(
            w.render('test', SimpleUploadedFile('test', b'content')),
            '<input type="file" name="test">',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:tests.py

示例2: test_readonly_fields

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_readonly_fields(self):
        """
        File widgets should render as a link when they're marked "read only."
        """
        self.client.force_login(self.superuser)
        response = self.client.get(reverse('admin:admin_widgets_album_change', args=(self.album.id,)))
        self.assertContains(
            response,
            '<div class="readonly"><a href="%(STORAGE_URL)salbums/hybrid_theory.jpg">'
            r'albums\hybrid_theory.jpg</a></div>' % {'STORAGE_URL': default_storage.url('')},
            html=True,
        )
        self.assertNotContains(
            response,
            '<input type="file" name="cover_art" id="id_cover_art">',
            html=True,
        )
        response = self.client.get(reverse('admin:admin_widgets_album_add'))
        self.assertContains(
            response,
            '<div class="readonly"></div>',
            html=True,
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例3: student_view_data

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def student_view_data(self):
        """
        Inform REST api clients about original file location and it's "freshness".
        Make sure to include `student_view_data=scormxblock` to URL params in the request.
        """
        if self.scorm_file and self.scorm_file_meta:
            return {
                'last_modified': self.scorm_file_meta.get('last_updated', ''),
                'scorm_data': default_storage.url(self._file_storage_path()),
                'size': self.scorm_file_meta.get('size', 0),
                'index_page': self.path_index_page,
            }
        return {} 
开发者ID:raccoongang,项目名称:edx_xblock_scorm,代码行数:15,代码来源:scormxblock.py

示例4: save_user_file

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def save_user_file(user, file, subdir, hashed=False):
    """
    Save user media file into sub-dir. \
    The `hashed`` param prevents file duplication
    """
    file_path = utils.generate_filename(file, hashed=hashed)
    name = os.path.join('spirit', subdir, str(user.pk), file_path)
    name = default_storage.save(name, file)
    file.name = os.path.basename(file_path)
    file.url = default_storage.url(name)
    return file 
开发者ID:nitely,项目名称:Spirit,代码行数:13,代码来源:forms.py

示例5: test_url

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_url(self):
        self.assertTrue(
            self.storage.url("my_file.txt").endswith("/test/my_file.txt"))
        self.storage.expiration_secs = 360
        # has some query-string
        self.assertTrue("/test/my_file.txt?" in self.storage.url("my_file.txt")) 
开发者ID:jschneier,项目名称:django-storages,代码行数:8,代码来源:test_azure.py

示例6: test_url_unsafe_chars

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_url_unsafe_chars(self):
        name = "my?file <foo>.txt"
        expected = "/test/my%3Ffile%20%3Cfoo%3E.txt"
        self.assertTrue(
            self.storage.url(name).endswith(expected))
        # has some query-string
        self.storage.expiration_secs = 360
        self.assertTrue("{}?".format(expected) in self.storage.url(name)) 
开发者ID:jschneier,项目名称:django-storages,代码行数:10,代码来源:test_azure.py

示例7: test_url_custom_endpoint

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_url_custom_endpoint(self):
        storage = azure_storage.AzureStorage()
        storage.is_emulated = True
        storage.custom_domain = 'foobar:123456'
        self.assertTrue(storage.url("my_file.txt").startswith('https://foobar:123456/')) 
开发者ID:jschneier,项目名称:django-storages,代码行数:7,代码来源:test_azure.py

示例8: test_template_media_file

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_template_media_file(self):
        t = Template('{{ file_url }}')
        rendered = t.render(Context({
            'file_url': default_storage.url('foo.txt')})).strip()
        self.assertTrue(
            "https://127.0.0.1:10000/devstoreaccount1/test_private/foo.txt?" in rendered)
        self.assertTrue("&amp;" in rendered)

        # check static files still work
        t = Template(
            '{% load static from staticfiles %}'
            '{% static "foo.txt" %}')
        self.assertEqual(
            t.render(Context({})).strip(),
            "https://127.0.0.1:10000/devstoreaccount1/test/foo.txt") 
开发者ID:jschneier,项目名称:django-storages,代码行数:17,代码来源:test_azure.py

示例9: test_name_clean_issue_609

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_name_clean_issue_609(self):
        """
        Should strip special characters when using the default storage
        """
        simple_file = SimpleFileModel()
        simple_file.foo_file = SimpleUploadedFile(
            name='foo%?:;~bar.txt',
            content=b'foo content')
        simple_file.save()
        self.assertEqual(simple_file.foo_file.name, 'foo_uploads/foobar.txt')
        self.assertTrue('foobar.txt' in simple_file.foo_file.url) 
开发者ID:jschneier,项目名称:django-storages,代码行数:13,代码来源:test_azure.py

示例10: test_save_small_file

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_save_small_file(self):
        with self.save_file():
            logging.info("content type: %s", default_storage.content_type("test.txt"))
            self.assertEqual(default_storage.open("test.txt").read(), b"test")
            self.assertEqual(requests.get(default_storage.url("test.txt")).content, b"test") 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:7,代码来源:tests.py

示例11: test_save_big_file

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_save_big_file(self):
        with self.save_file(content=b"test" * 1000):
            logging.info("content type: %s", default_storage.content_type("test.txt"))
            self.assertEqual(default_storage.open("test.txt").read(), b"test" * 1000)
            self.assertEqual(requests.get(default_storage.url("test.txt")).content, b"test" * 1000) 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:7,代码来源:tests.py

示例12: test_url

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_url(self):
        with self.save_file(name="folder/test?+123.txt"):
            url = default_storage.url("folder/test?+123.txt")
            logging.info("url: %s", url)
            response = requests.get(url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"test")
            self.assertEqual(response.headers['Content-Type'], "text/plain")

            auth = oss2.Auth(settings.OSS_ACCESS_KEY_ID, settings.OSS_ACCESS_KEY_SECRET)
            bucket = oss2.Bucket(auth, settings.OSS_ENDPOINT, settings.OSS_BUCKET_NAME)
            if bucket.get_bucket_acl().acl == 'private':
                self.assertEqual(url.find('.txt?') > 0, True)
            else:
                self.assertEqual(url.find('.txt?') > 0, False) 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:17,代码来源:tests.py

示例13: test_url_cn

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_url_cn(self):
        objname = to_unicode("本地文件名.txt")
        logging.info("objname: %s", objname)
        data = oss2.compat.to_bytes('我的座右铭')
        with self.save_file(objname, data) as name:
            self.assertEqual(name, objname)
            url = default_storage.url(objname)
            logging.info("url: %s", url)
            response = requests.get(url)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, data)
            self.assertEqual(response.headers['Content-Type'], "text/plain") 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:14,代码来源:tests.py

示例14: test_static_url

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def test_static_url(self):
        with self.save_file(storage=staticfiles_storage):
            url = staticfiles_storage.url("test.txt")
            logging.info("url: %s", url)
            response = requests.get(url)

            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.content, b"test")
            self.assertEqual(response.headers['Content-Type'], "text/plain") 
开发者ID:aliyun,项目名称:django-oss-storage,代码行数:11,代码来源:tests.py

示例15: get_thumbnail_picture_url

# 需要导入模块: from django.core.files.storage import default_storage [as 别名]
# 或者: from django.core.files.storage.default_storage import url [as 别名]
def get_thumbnail_picture_url(self):
        url = ""
        picture_path, thumbnail_path = self.get_picture_paths()

        if thumbnail_path:
            url = (storage.url(thumbnail_path)
                   if storage.exists(thumbnail_path)
                   else self.picture.url)

        return url 
开发者ID:PacktPublishing,项目名称:Django-2-Web-Development-Cookbook-Third-Edition,代码行数:12,代码来源:models.py


注:本文中的django.core.files.storage.default_storage.url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。