Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Celery task ar hour=00 and minute=00
I am running one periodic celery task for everyday midnight, i.e with args hour=00, mins=00. The issue I am facing it, when it is running at a exact time it runs for previous day i.e timezone.now().date is for previous day. So my question is doesn't the day change at 00:00 or should I run the task on 00:01 -
Django models - primary key constraint naming
Is there a way to force the naming of the primary key constraint in Django? For example, when we use UniqueConstraint() we can define the name of the constraint (constraint_name) like below: class SomeTable(models.Model): col1 = models.DateField(primary_key=True) col2 = models.CharField(max_lenght=123) col3 = models.BooleanField() class Meta: constraints = [ models.UniqueConstraint(fields=["col1", "col2"], name="constraint_name") ] How can this be done for the primary key constraint name? The SQL equivalent would be: ALTER TABLE ONLY some_table ADD CONSTRAINT "old_primary_key_name" PRIMARY KEY (col1); or renaming if we do migrations ALTER TABLE some_table RENAME CONSTRAINT "old_primary_key_name" TO "new_primary_key_name" -
how to get queryset in django template ListView
I print the teacher_name stored in the'School' class model as a full list When you click the period by creating a radio button for all and periods, I want to print out the query results. There are three models, the first model is a class school The second model is a class student enrolled in each school, and the third model is Each student's entrance date (Attribute). Unlike common sense, there are students who enter every month. When I click on a period and click on a date in the datepicker widget The url query is generated as shown below. /?optionRadios=period&from_date=2020-12-01&to_date=2020-12-31 The problem seems to be that when I do Attribute.objects.filter(), from_date and to_date are not recognized. [models.py - School] class School(models.Model): school_name = models.CharField(max_length=50, blank=False) ... [models.py - Student] class Student(models.Model): student_name = models.CharField(max_length=50, blank=False) school = models.Foreignkey(School, on_delete=models.SET_NULL, null=True, blank=True) [models.py - Attribute] class Attribute(models.Model): entrance_date = models.DateField(blank=False) student = models.Foreignkey(Student, on_delete=models.SET_NULL, null=True, blank=True) [views.py - School] class StudentListView(ListView): model = School context_object_name = 'schools' template_name = 'student_list.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) school_id = context['schools'][0] student = Student.objects.filter(school_id=school_id) to_date = self.request.GET.get('to_date') from_date = self.request.GET.get('from_date') context['option_radio'] = self.request.GET.get('optionRadios') context['entrance_count'] = Attribute.objects.filter( entrance_date__lte=to_date, entrance_date__gte=from_date, student_id__in=student).count() return context [template … -
Call multiple fields in another field at once based on type of the same model in Django
I have the following models: class Test1(BaseModel): name = models.CharField(max_length=128, null=True, blank=True) def __str__(self): return self.name class Test2(BaseModel): name = models.CharField(max_length=128, null=True, blank=True) def __str__(self): return self.name class Test3(BaseModel): name = models.CharField(max_length=128, null=True, blank=True) def __str__(self): return self.name class Test(models.Model): name = models.CharField(max_length=128, null=True, blank=True) test1 = models.ForeignKey(Test1, blank=True, null=True, on_delete=models.SET_NULL) test2 = models.ManyToManyField(Test2, null = True, blank = True, related_name='test3s') test3 = models.ManyToManyField(Test3, blank=True, null=True, related_name='test3s') custom_values = CustomModel(m2m_fields=[test2, test3], fks=[test1]) def __str__(self): return self.name In the custom_values field I am passing a custom class for some functionality with the values of the same model. Now this is working correctly. But in some models there are more than five m2m and ten fk fields. So instead of specifying them every time is there any way for me to specify something like this? - custom_values = CustomModel(m2m_fields='__all__', fks='__all__') Here I would like to pass only m2m for m2m_fields and only foreignkey for fks. -
What would be the jQuery function to change the boolean value of a Toggle Switch?
What would be the corresponding jQuery function or Ajax function to change these toggle values so that if the toggle switch is on the value would be changed to True? forms.py from django import forms class CsvForm(forms.Form): shipping_us = forms.BooleanField(required=False) shipping_europe = forms.BooleanField(required=False) shipping_asia = forms.BooleanField(required=False) views.py def submit(request): csv_form = '' if request.method == 'POST': csv_form = CsvForm(request.POST) if csv_form.is_valid(): shipping_us = csv_form.cleaned_data['shipping_us'] shipping_europe = csv_form.cleaned_data['shipping_europe'] shipping_asia = csv_form.cleaned_data['shipping_asia'] context= {'shipping_us': shipping_us,'shipping_europe': shipping_europe,'shipping_asia': shipping_asia,'csv_form':csv_form.} return render(request,'submit.html', context) else: csv_form = CSVForm() context = {'csv_form':csv_form} return render(request,'submit.html',context) else: return render(request,'submit.html') index.html <form accept-charset="UTF-8" action="{% url 'submit'%}" method="POST" enctype="multipart/form-data"> {% csrf_token %} <div class="form-row"> <div class="name">Shipping Options/US</div> <label class="switch"> <input type="checkbox" id="checkbox" name ="shipping_us" value="{{ shipping_us }}"> <span class="slider round"></span> </label> </div> <div class="form-row"> <div class="name">Shipping Options/Europe</div> <label class="switch"> <input type="checkbox" id="checkbox" name ="shipping_europe" value="{{ shipping_europe }}"> <span class="slider round"></span> </label> </div> <div class="form-row"> <div class="name">Shipping Options/Asia</div> <label class="switch"> <input type="checkbox" id="checkbox" name="shipping_asia" value="{{ shipping_asia }}"> <span class="slider round"></span> </label> </div> </form> submit.html <p>{{ shipping_us }}</p> <p>{{ shipping_europe}}</p> <p>{{ shipping_asia }}</p> The submit.html displays False False False What would be the corresponding jQuery function or Ajax function to change these toggle values so that if the toggle switch is on the … -
Tracking GenericForeignKey changes for django-simple-history
If the model's field is just a regular ForeignKey, I can track changes no problem: # models.py class Foo(models.Model): history = HistoricalRecords() bar = ForeignKey(Bar) # test.py b1 = Bar.objects.create() b2 = Bar.objects.create() b3 = Bar.objects.create() foo = Foo.objects.create(bar=b1) foo.bar = b2 foo.save() foo.bar = b3 foo.save() for i in foo.history.all(): print(i.bar) # Returns: # b3 # b2 # b1 However, if my model is a GenericForeignKey, I get this error message: AttributeError: 'HistoricalFoo' object has no attribute 'content_object' # models.py class Foo(models.Model): history = HistoricalRecords() content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey("content_type", "object_id") bar = ForeignKey(Bar) # test.py b1 = Bar.objects.create() b2 = Bar.objects.create() b3 = Bar.objects.create() foo = Foo.objects.create(content_object=b1) self.assertEqual(foo.content_object, b1) # no problem foo.bar = b2 foo.save() self.assertEqual(foo.content_object, b2) # no problem foo.bar = b3 foo.save() self.assertEqual(foo.content_object, b3) # no problem for i in foo.history.all(): print(i.content_object) # Gives error: AttributeError: 'HistoricalFoo' object has no attribute 'content_object' Hhowever, django-simple-history does seem to be able to provide the content_type and object_id so I can manually construct the content_object: for i in foo.history.all(): print(i.content_type.model_class().objects.get(pk=i.object_id)) # Returns: # b3 # b2 # b1 Is this the only/best/correct approach? -
Cannot query "Python Tutorials Teaser": Must be "Subject" instance
I am creating E-Learning website and I want to show "Course Content or Lession" as a playlist which is related to subject. Like that image but I am getting error Cannot query "Python Tutorials Teaser": Must be "Subject" instance. Python Tutorials Teaser is title of the lession. view.py def allsubject(request): subj = Subject.objects.all() context = {'subj': subj} return render(request, 'allsubject.html', context) def pvideos(request, slug): vds = Videos.objects.filter(slug=slug).first() coursecontent = Videos.objects.filter(subject=vds) context = {'vds':vds, 'coursecontent':coursecontent} return render(request, 'pvideos.html', context) models.py class Videos(models.Model): sno = models.AutoField(primary_key=True) title = models.CharField(max_length=500) cont = models.TextField() vurl = models.URLField(max_length=200) subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='videos') position = models.PositiveSmallIntegerField(verbose_name="videono.") slug = models.CharField(max_length=130) timeStamp = models.DateTimeField(default=now) def __str__(self): return self.title pvideo.html {% extends 'base.html' %} {% block title %}Free Video Course {% endblock title %} {% block body %} <div class="container"> <div class="embed-responsive embed-responsive-21by9"> <iframe class="embed-responsive-item" src="{{vds.vurl}}" allowfullscreen></iframe> </div> <ul class="nav nav-tabs" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link active font-weight-bold" id="home-tab" data-toggle="tab" href="#overview" role="tab" aria-controls="home" aria-selected="true">Overview</a> </li> <li class="nav-item"> <a class="nav-link font-weight-bold" id="profile-tab" data-toggle="tab" href="#coursecontent" role="tab" aria-controls="profile" aria-selected="false">Course Content</a> </li> </ul> <div class="tab-content" id="myTabContent"> <div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="home-tab"> <h2>{{vds.title}}</h2> <p>{{vds.cont|safe}}</p> </div> <div class="tab-pane fade" id="coursecontent" role="tabpanel" aria-labelledby="profile-tab"> {% for c in coursecontent %} {{c.title}} {% … -
Json.parse() automatically modifying values
I am wondering how this can happen, I tried visiting My API (Django Rest Api) directly from browser, and I got correct results, But when using JSON.parse() it is modifying user id. Can any one help me what should I do? Expected Results: { avatar: "a76024fba4dbe97464128190a5b8cc91" discriminator: 3971 flags: 131136 id: 347724952100667394 last_login: "2021-04-19T03:22:27.431275Z" locale: "en-US" mfa_enabled: true name: "WiperR" public_flags: 131136 } First result logged before using JSON.parse(), Later one logged after using JSON.parse(). -
raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues
File "D:---\api\drf-rest-auth\lib\site-packages\django\core\management\base.py", line 469, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues: ERRORS: Employee.User: (auth.E003) 'User.username' must be unique because it is named as the 'USERNAME_FIELD'. System check identified 1 issue (0 silenced). class User(AbstractUser): username=models.CharField(max_length=255) email=models.EmailField(('email adress'),unique=True) USERNAME_FIELD ='email' REQUIRED_FIELD = ['username','first_name','last_name'] def __str__(self): return "{}".format(self.email) -
Django AUTH_PASSWORD_VALIDATORS check for symbols and other requirements
Is it possible to validate password requirements such as: One capital letter Two symbols using Django's inbuilt password management? e.g. these: django.contrib.auth.password_validation.UserAttributeSimilarityValidator django.contrib.auth.password_validation.MinimumLengthValidator django.contrib.auth.password_validation.CommonPasswordValidator django.contrib.auth.password_validation.NumericPasswordValidator I found the following Python package that does what I'd like but I'm wondering if it can be done natively: https://pypi.org/project/django-password-validators/ Thanks! -
When i am creating a ticket using api code with fresh desk it showing error - FieldFile is not JSON serializable
TypeError at /web/ticketcreation/ Object of type FieldFile is not JSON serializable this is my views.py def ticketcreation(request): if request.method == 'POST': current_user = "" mem_obj = Member.objects.all() for mem in mem_obj: # print("Expand ", mem.Email, mem.flag) if mem.flag == 1: current_user = mem.Email ticket = Ticket(Email=current_user, to=request.POST.get('to'), subject=request.POST.get('subject'), cc=request.POST.get('cc'), module=request.POST.get('module'), priority=request.POST.get('priority'), message=request.POST.get('message'), choosefile=request.POST.get('choosefile')) ticket.save() api_key = "********" domain = "*********" password = "***********" headers = {'Content-Type': 'application/json'} ticket = { 'subject': ticket.subject, 'description': ticket.message, 'email': ticket.Email, 'priority': 1, 'status': 2, 'cc_emails': [ticket.to, ticket.cc], 'attachemnts':ticket. choosefile } r = requests.post("https://" + domain + ".freshdesk.com/api/v2/tickets", auth=(api_key, password), headers=headers, data=json.dumps(ticket)) if r.status_code == 201: print ("Ticket created successfully, the response is given below" + str(r.content)) print ("Location Header : " + str(r.headers['Location'])) else: print ("Failed to create ticket, errors are displayed below,") response = json.loads(r.content) print (response["errors"]) print ("x-request-id : " + r.headers['x-request-id']) print ("Status Code : " + str(r.status_code)) # ticket = TicketForm(request.POST, request.FILES) # if ticket.is_valid(): # ticket.save() return render(request, 'web/ticketcreation.html', {'msg': 'Ticket created successfully', 'current_user':current_user}) Can any one please help me -
How to get all the column names in the DB using Django [duplicate]
I need to get all the column names for a model using django My model looks like the following: class network_asset(models.Model): asset_tag = models.CharField(max_length=150, null=True, blank=True) stack_no = models.CharField(max_length=3, blank=True, null=True) device_role = models.CharField(max_length=150, blank=True, null=True) device_type = models.CharField(max_length=150, blank=True, null=True) serial_number = models.CharField(max_length=150, null=True, blank=True) host_name = models.CharField(max_length=150, null=True, blank=True) sw_fw_version = models.CharField(max_length=150, null=True, blank=True) And I need to get all the column names from the DB without values (fields from the model) in my views.py -
How to Serialize Queryset.values in Django?
Suppose, I have a query: qs = demo.objects.filter(id=id).values_list('name','price') And I have a serializer: Class DemoSerialzier(serialzier.Modelserialzier): class Meta: model = Demo fields = ['name','price'] How do I serialize my qs? when I pass my qs through the serializer it gives an AttributeError. Where Django tried to find a field on the serializer and the tuple object has no attribute 'name'. -
Alternatives to making a MOBILE APP! - For communicating data
So I have a website and it generates reports using data (Picture and small description) from people in the field. As people walk around they can take a picture and a description and later on it will appear on the website to edit. I have my first solution which is to create a mobile app for both android and apple and have a database stored on the phone of the pic and description that then uploads to the website once the phone connects to wifi. FINAL QUESTION: I'm looking for a much simpler solution if there is one out there, especially because uploading a mobile app to the AppStore and to apple is somewhat a painstaking process in my research. I don't need anything really fancy just what meets the description and I'm wondering if anyone has any experience or brilliance in the matter. If anyone has any information about something similar that has been done in the past that would go a long way too. Thanks!! -
How to declare author to current user in Model serializer?
I have Post model: class Post(models.Model): title = models.CharField(max_length=50) text = models.CharField(max_length=1000) published_date = models.DateTimeField(auto_now_add=True) author = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE ) category = models.ForeignKey(Category, on_delete=models.CASCADE) And a view: @api_view(['GET', 'POST']) def posts(request): if request.method == 'GET': post_list = Post.objects.all() serializer = PostSerializer(post_list, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = PostSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors) And serializer: class PostSerializer(serializers.ModelSerializer): id = serializers.IntegerField(read_only=True) author = UserSerializer(read_only=True) category = CategorySerializer(read_only=True) author_id = serializers.IntegerField(write_only=True) category_id = serializers.IntegerField(write_only=True) class Meta: model = Post fields = ('id', 'title', 'text', 'published_date', 'author', 'category', 'category_id', 'author_id') I want to send POST request like {"title":"some title", "text":"some text", "category_id"=1, "author_id":???} where ??? current user id. How can I do it? -
How can I get values from a view in Django every time I access the home page
I currently have the following view created in Django: @login_required def retrieve_from_db(request): some_ids = get_some_data() context = {'some_ids': some_ids} return render(request, 'index.html', context) This is my urls.py: from django.urls import path from . import views app_name = 'blabla' urlpatterns = [ path('', views.another_view, name='index'), path('', views.retrieve_from_db, name='index'), ... ... ... ] And this is part of my index.html <div> <select name="myIdList" id="myIdList"> {% for some_id in some_ids %} <option value="{{ some_id }}">{{ some_id }}</option> {% endfor %} </select> </div> I would like to know how can I get the results from the function retrieve_from_db(). What I want is that every time I access the home page, by default the selects are populated with the result of the view. All I have found so far on StackOverflow have been answers using forms in which the user somehow has to perform some action to trigger the POST, is there any way to do all of this without the user having to press any buttons or perform an action? simply every time the page loads, get the results of the retrieve_from_db() function defined in the view. -
How can I send Notification to another user in Django
When I create a task and assign it to another user, the assigned user will get a notification that someone added you to a task. The assigned user can approve/declined the task. If the invitation is accepted the task will visible to the user otherwise invitation declined notification will be returned to the author. This is my models.py from django.db import models from django.contrib.auth.models import User # Create your models here. class Project(models.Model): author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='project_author') assigned_to = models.ForeignKey(User, on_delete=models.CASCADE, related_name='assigned_to') title = models.CharField(max_length=264, verbose_name="Title ", unique=True) description = models.TextField(verbose_name="Description ") files = models.FileField(upload_to='blog_images', verbose_name="Image", blank=True) publish_date = models.DateTimeField(auto_now_add=True) update_date = models.DateTimeField(auto_now=True) class Meta: ordering = ['-publish_date', ] def __str__(self): return self.title Views.py class CreateProject(LoginRequiredMixin, generic.CreateView): model = Project template_name = 'ProjectApp/create_project.html' fields = ('assigned_to', 'title', 'description',) def form_valid(self, form): project = form.save(commit=False) project.author = self.request.user project.save() return HttpResponseRedirect(reverse('ProjectApp:dashboard')) -
Django Faker Recursive Foreign Key
I am trying to create a seeding script using Faker. In my models.ContentCategory, the parent_category has a recursive foreign key. However, I could not find a way to translate this into my faker script. I am really open to all kinds of helps! here is my models.py: class ContentCategory(models.Model): name = models.CharField(blank=False, null=False, max_length=100) description = models.CharField(blank=False, null=False, max_length=100) parent_category = models.ForeignKey( "self", on_delete=models.DO_NOTHING, null=True, blank=True, parent_link=True, ) # down here should be fixed after creating the sections model parent_section = models.ForeignKey( Sections, on_delete=models.CASCADE, blank=True, null=True ) def __str__(self): return self.name class Meta: verbose_name = "content category" verbose_name_plural = "Content Categories" and here is the handler snippet: #seeding Content Category for _ in range(4): name = fake.word(ext_word_list=None) description = fake.sentence(nb_words=15, variable_nb_words=True, ext_word_list=None) #creating ids and parent ids cid = random.randint(1,4) # creating key for Sections ptid = random.randint(1,14) ContentCategory.objects.create( name=name, description=description, parent_category=cid, parent_section=ptid ) check_content_categories = ContentCategory.objects.count().all() here is the full error log: python manage.py seed Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/myyagis/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/home/myyagis/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/myyagis/.local/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/home/myyagis/.local/lib/python3.8/site-packages/django/core/management/base.py", line … -
Django password validator for multiple symbols
Creating password requirements for a user in Django using: django.contrib.auth.password_validation.UserAttributeSimilarityValidator django.contrib.auth.password_validation.MinimumLengthValidator django.contrib.auth.password_validation.CommonPasswordValidator django.contrib.auth.password_validation.NumericPasswordValidator However, when I use the password $a1ABCD%#@ it gives me the error message: At least one special character (punctuation, brackets, quotes, etc.), at least one lowercase character, at least one uppercase character, at least one digit, at least 8 chars. $a1ABCD@ seems to work though. Any ideas? -
Django media folder is not created when uploading image
settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') models.py class Profile(models.Model): img=models.ImageField(upload_to='media',null=True) bio=models.TextField(max_length=50, null=True) user=models.OneToOneField(User,related_name='profile',on_delete=models.CASCADE) urls.py urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) so basically after I upload an image no media folder is created, i am working on latest version of django, if more info need to be provided, please tell. -
I cannot load GLTF into Three.JS script within Django app
I am adding a script with Three.Js to an HTML file. I want to load a GLTF model but when I try to add it, the canvas goes completely black. ... const loader = new GLTFLoader(); loader.load( 'testModel.gltf', function ( gltf ) {scene.add( gltf.scene );}); ... -
How can I pass information from an item to a Modal in django to edit it?
I have a template where I'm showing with a 'for' my elements, and those elements have a Edit button, so what I want to do, is when the user clicks edit, a pop up appears with the form and the information of that item. So I don't know how to do that:( -
how to edit style for login / signup pages using allauth django
how to edit style for login / signup pages using allauth django , when i open forms.py file it don't know how to edit style and add bootstrap there is many code i don't know where i should edit to add style i try edit login html page but i can't do anything because it's just like this <form class="login" method="POST" action="{% url 'account_login' %}"> {% csrf_token %} {{ form.as_p }} {% if redirect_field_value %} <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" /> {% endif %} </form> forms.py from allauth : class LoginForm(forms.Form): password = PasswordField(label=_("Password"), autocomplete="current-password") remember = forms.BooleanField(label=_("Remember Me"), required=False) user = None error_messages = { "account_inactive": _("This account is currently inactive."), "email_password_mismatch": _( "The e-mail address and/or password you specified are not correct." ), "username_password_mismatch": _( "The username and/or password you specified are not correct." ), } def __init__(self, *args, **kwargs): self.request = kwargs.pop("request", None) super(LoginForm, self).__init__(*args, **kwargs) if app_settings.AUTHENTICATION_METHOD == AuthenticationMethod.EMAIL: login_widget = forms.TextInput( attrs={ "type": "email", "placeholder": _("E-mail address"), "autocomplete": "email", } ) login_field = forms.EmailField(label=_("E-mail"), widget=login_widget) elif app_settings.AUTHENTICATION_METHOD == AuthenticationMethod.USERNAME: login_widget = forms.TextInput( attrs={"placeholder": _("Username"), "autocomplete": "username"} ) login_field = forms.CharField( label=_("Username"), widget=login_widget, max_length=get_username_max_length(), ) else: assert ( app_settings.AUTHENTICATION_METHOD == AuthenticationMethod.USERNAME_EMAIL ) login_widget … -
Django Graphene DataLoader fatal error for Redis call at a certain number of items
I have this DataLoader I've been using for loading about 50 or less items at a time. Each one of those items would potentially have some metadata in Redis I would need to send to the client. To a more efficient single request to Redis I am using a DataLoader. I have a new use case where I am loading more than 100 items and making the same associated Redis query for each item. When this happens I receive these errors: Fatal Python error: Cannot recover from stack overflow. Python runtime state: initialized # ... graphql.error.located_error.GraphQLLocatedError: maximum recursion depth exceeded while calling a Python object My DataLoader code: class MetadataDataLoader(DataLoader): def batch_load_fn(self, components_ids): # Setup Redis query client = clients.redis.get_redis_client() pipe = client.pipeline() for component_id in components_ids: pipe.hgetall(f"component_metadata:{component_id}") # Fetch all the data in a single call metadata_raw = pipe.execute() # Transform Redis byte strings to JSON string metadata_clean = [] for metadata in metadata_raw: metadata_clean.append(json.dumps({y.decode("utf-8"): metadata.get(y).decode("utf-8") for y in metadata.keys()})) return Promise.resolve(metadata_clean) My Redis library: redis-py-cluster = "2.1.0" -
Django Templates - How can I reference context inside HTML tags?
I'm trying to create an email template. I've set up my context and everything is fine, however when it comes to passing a URL link through an <a> tag, im not sure where/how to place the context variable: Here is how I do it: <td> <a href="{{url}}" >Verify Email</a > </td> However, I don't seem to get the expected results, did I use the url variable wrong above? context = { 'name': user.first_name, 'url': absurl } html = render_to_string('email/email_confirm.html', context) The name context is working just fine on my template.