Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Dj-Gravatar is a Python package to display avatars using Gravatar on a website developed using Django Framework.
In the terminal/PowerShell, type
python -m pip install dj-gravatar
If you do not have pip
, then download the package from here, unzip it and keep it in your Django project's root directory (as an app).
In the terminal, type
sudo pip3 install dj-gravatar
If you are in a virtual environment, type
pip install dj-gravatar
If you do not have pip
, then download the package from here, unzip it and keep it in your Django project's root directory (as an app).
Suppose the directory structure of your project is like this.
Django_Project
│ db.sqlite3
│ manage.py
│
├───pages
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ └───templates
│ │ base.html
│ │
│ └───pages
│ about.html
│ index.html
│
└───Django_Project
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
In Django_Project/settings.py
,
...
INSTALLED_APPS = [
...
'dj_gravatar' # NOTE: underscore(_) is used instead of hyphen(-)
...
]
...
In the Django Template (.html
file) where you want to show the gravatar,
{% load gravatar %}
...
<img src="{% gravatar_url 'email@mail.com' 200 %}" alt="profile-pic">
...
The above code outputs like this:
<img src="http://www.gravatar.com/avatar/267f3587edc9b64d8e80ee7eca8abbcb?s=200&d=" alt="profile-pic">
<!-- OR -->
<img src="http://www.gravatar.com/avatar/[hash]?s=200&d=" alt="profile-pic">
The argument s=200
represents the size of the image (size=200px
). Default size is 80px.
You can also use the following snippet to achieve the same as above:
{% load gravatar %}
...
{% gravatar 'email@mail' 200 "alt='profile-pic'" %}
...
You can use any HTML attribute instead of alt
, like style
. But only use one optional attribute at a time, Otherwise you will get TemplateSyntaxError
.
If you want to use https://.../
instead of the default http://.../
, then add the following setting in your settings.py
file.
GRAVATAR_SECURE = True # Default False
If any email address has no matching Gravatar image, then, a default image is shown. There are the following types of default images:
You can see here how each type of default image looks like.
To show a particular default image out of the above, add the following setting to your settings.py
file.
GRAVATAR_DEFAULT_URL = 'identicon' # Choose any one of the above
Contributions are welcome. If you spot any bug(s), have a feature request, or anything else, don't hesitate to do a Pull Request, or opening an issue from here.
FAQs
Use Gravatar in a Django Website
We found that dj-gravatar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.