- Как использовать загруженный шрифт в проекте django вместо API шрифтов Google
- 1 ответ
- Python & Django как указать локальные шрифты?
- Пикод
- Saved searches
- Use saved searches to filter your results more quickly
- License
- cuducos/django-custom-font
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Как использовать загруженный шрифт в проекте django вместо API шрифтов Google
Я нигде не могу найти решение своей проблемы, поэтому надеюсь на некоторую помощь. Я новичок в программировании, а также в django. Я следовал следующему руководству до начала части 4.
Все идет нормально. Теперь я нашел в сети новый шрифт, который я хотел бы использовать вместо шрифта Google, который используется в руководстве, для «логотипа» django на верхней панели (он называется Crimson Foam).
Проблема в том, что я понятия не имею, как использовать его в моем файле base.html и что делать с моими файлами css (я видел, что вам, очевидно, нужно их использовать). Мои статические файлы организованы так:
-- static |--fonts | |--crimson_foam.ttf | |--css |-- app2.css |-- bootstrap files
Django Boards " rel="stylesheet" type="text/css"> "> "> Rest of the html file
Я пробовал 2 разные версии файла .css:
Статический / css / app2.css
Честно говоря, я поражен тем, сколько еще нужно знать о django. Я знаю, что есть похожие потоки, но они не говорят о базовом файле html, и я недостаточно продвинут, чтобы увидеть, где что-то изменить.
Заранее спасибо всем за чтение этого длинного текста!
1 ответ
Для каждого, кто нашел свой путь к моему вопросу, я нашел ответ:
В моем решении используется метод css под названием @ font-face.
Чтобы достичь желаемого результата, мы должны добавить следующий код в наш файл css:
@font-face < font-family: "Any name you want to give your font for further use"; src: url("either an absolute path from your homedirectory or a relative path"); ># in my Case the code looked like this: @font-face < font-family: "Crimson Foam"; src: url("../fonts/crimson_foam.ttf); >
Таким образом вы добавите свой шрифт с названием «Crimson Foam» в свой пул используемых шрифтов. Вы можете поместить множество методов @ font-face в один файл .css.
Чтобы использовать только что объявленное имя шрифта, вы можете сделать одно из двух:
html-tag.your_method_name < font-family: "One of the fonts you assigned with @font-face", style (like regular or cursive); font-size: A percantage (like 150%) or pixel like "36px"; ># In my case, that looked like this: h1.crimson_method
После того, как вы это сделаете, вы также должны упомянуть имя вашего метода в вашем html файле в части . Это могло выглядеть так:
Django Boards Rest of the html file
Ссылки, которые я использовал в разделе html своих вопросов, используются для ссылки на веб-сайт, с которого у меня были шрифты Google. Существует также метод внедрения шрифтов Google, но по этой теме есть множество хороших руководств, таких как this один в Интернете.
Python & Django как указать локальные шрифты?
Вы используете устаревший браузер. Этот и другие сайты могут отображаться в нем неправильно.
Необходимо обновить браузер или попробовать использовать другой.
Пикод
Новичок
Добрый день! Столкнулся с проблемой локальных шрифтов. Есть страница pdf_os.html там шрифты прописаны в тег style но мне надо статистический указать шрифты чтоб и на сервере оно работало. Попробовал сверху html страницы прописать <% load static %>и в основной main.css добавил @font-face < font-family: 'Arial'; src: local('Arial'), url('../static/main/fonts/arial.ttf') format("truetype"); >но это не помогло. Еще попробовал втутри тега style прописать @font-face < font-family: 'Arial'; src: local('Arial'), url('<% static 'main/fonts/arial.ttf' %>format(«truetype»)’); > это тоже немогло.Подскажите где я ошибся или как решить по другому
%>
@media print < @font-face < font-family: 'Arial'; src: url('C:\Users\SVT4\PycharmProjects\tmc-webap\itwebtmc\main\static\main\fonts\arial.ttf') format("truetype"); >@font-face < font-family: 'DejaMono'; src: url('C:\Users\SVT4\PycharmProjects\tmc-webap\itwebtmc\main\static\main\fonts\DejaVuSansMono.ttf') format("truetype"); >@font-face < font-family: 'DejaMono'; src: url('C:\Users\SVT4\PycharmProjects\tmc-webap\itwebtmc\main\static\main\fonts\DejaVuSerif-Bold.ttf') format("truetype"); font-weight: bold; >body < font-family: 'Arial'; font-family: 'DejaMono'; >> @page < size: a4 portrait; @frame header_frame < /* Static Frame */ -pdf-frame-content: header_content; left: 50pt; width: 512pt; top: 50pt; height: 40pt; >@frame content_frame < /* Content Frame */ left: 50pt; width: 512pt; top: 90pt; height: 632pt; >@frame footer_frame < /* Another static Frame */ -pdf-frame-content: footer_content; left: 50pt; width: 512pt; top: 810pt; height: 20pt; >> table Общий список of Названия Инв.номер Серийный номер Дата принятие Дата списание > > > > > Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Simple example of using custom fonts in Django
License
cuducos/django-custom-font
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Django with custom CSS FONT
A friend of mine asked for a straightforward example about how to use a custom font in Django. Here it is ; )
In a Python 3 (virtual) environment:
Simply follow Django’s default:
$ python manage.py runserver
This repo contains only 3 commits. Here is a summary of what they do.
1. Basic Django installation
This install Django and sets a home page at the root of the server that just renders core/templates/core/index.html .
Runnning the server and opening the home page you should see a heading with your browser’s custom font.
2. Set basic CSS & static files
This makes the basic setup for Django to handle and serve static files. In order to test it to see if works, it applies a custom font on h1 HTML tags.
Runnning the server and opening the home page you should see the heading with a sans-serif font.
3. Use Django ITC Std font
This commit uses Django ITC Std’s .otf file to load a custom font and applies it to h1 HTML tags.
Runnning the server and opening the home page you should see the heading with this sample custom font.
About
Simple example of using custom fonts in Django