Rendering data from a dictionary inside json after saving data into JSONField in Django
I am working on a django project whereby I am using JSONField to save data into the database of the model. Everything works fine but I am having issues when trying to render the data into the html template. The data saved into the database is as shown below.
{'degree': ['BSc','MSc'],
'designition': [
'content writer',
'data scientist',
'systems administrator',
],
'email': 'maunarokguy@gmail.com',
'name': 'Brian Njoroge',
'phone': '+918511593595',
'skills': [
'Python',
' C++',
'Power BI',
'Tensorflow',
'Keras',
'Pytorch',
'Scikit-Learn',
'Pandas',
'NLTK',
'OpenCv',
'Numpy',
'Matplotlib',
'Seaborn',
'Django',
'Linux',
'Docker'],
'total_exp': 3,
'university': ['gujarat university', 'wuhan university', 'egerton university']}
I am looking for a way to render them such that in the html, I will have something that displays the dictionary data inside skills and university as a list. Here is the template for loop
{% for skill in user.profile.json_data %}
{{skill}}
{% endfor %}
And here is the models
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
avatar = models.ImageField(default='default.jpg', upload_to='profile_images')
bio = models.TextField()
resume = models.FileField('Upload Resumes', upload_to='resumes/', null=True, blank=True,default='resume.docx')
json_data = models.JSONField(null=True, blank=True)
Here is the views
@login_required
def myprofile(request, user_id):
profile = Profile.objects.get(id=user_id)
context = {'profile':profile}
return render(request, 'user/profile.html', context)