當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。