Vladislav
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
cvrl
Hey there!
Can you help me, please?
I have this model:
class SomeIP(model.Models):
server_name = models.CharField(max_length=100)
ip = models.CharField(max_length=20)
mod = models.ForeignKey(Mod, on_delete = models.CASCADE, default=None)
user = models.ForeignKey(User, on_delete = models.CASCADE, default=None)
How can I take only some ‘ip’ and ‘server_name’ WHERE mod=some_mode_id AND user=some_user_id?
Mukhil
how can call url name inside js file
urls.py
path('htmltest/', views.vhtmltest, name='nhtmltest'),
java.js
{% url 'nhtmltest' %}
it is not working
any another option for call url inside java files
Hernan
cvrl
virat kohli
Yes
Can you tell how to do that
rtg
hi! ¿what is this console error? Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://googleads.g.doubleclick.net/pagead/id. (Reason: CORS request did not succeed). Status code: (null).
Mirco
rtg
ok
python
In django mvt
{% for message in messages %}
{{message}}
{% endfor %}
python
python
python
You can update javascript during page loading
python
python
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Have you check any templates you render
But you not put app name in app section in setting.py
python
Tb10
Hi, thinking about a django app to manage reminders. ie. remember to change oil every x hours.
models.py
WhatTodo.interval # 4 hours
WhenTodo.next # at 18 hours (current 14 hours + interval) (Foreign key to WhatTodo)
History.last # current data 14 hours (Foreign key to WhenTodo)
just an advice: is there already somenting similar,these models are meaningful?
mohammed
class Customer(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
class Meta:
indexes = [
models.Index(fields=['last_name', 'first_name']),
models.Index(fields=['first_name'], name='first_name_idx'),
]
mohammed
why we use indexes???
💻
Hi, I need helping on encrypting a zip file. I want to encrypt it after I create the zip file. Any tip? Code -> if form.is_valid():
zip_file = BytesIO()
with zipfile.ZipFile(zip_file, mode='w') as zf:
for file in request.FILES.getlist('file'):
#Convert to zip
zf.writestr(file.name,file.read())
file_data = File(user=request.user,file=file)
zip_file.seek(0)
Fawzul
Hi guys i need help in my django in the model.py i didnt put my primary key so it defaults create a field id now when i delete it and migrate it it says error please i really need this help can anyone help me please
D3mah
The Black Dev
python
.
i'm trying to update a staff object that has department forign key and i still get this error
Cannot assign "'1'": "Staff.department" must be a "Department" instance.
I tried to
before
worker.department = request.POST.get('department')
i tried to do somethind like:
worker.department.name = request.POST.get('department')
the error stop accouring but wehen i click save nothing changed
Any solutions?
python
Share ORM
python
Query
.
class Department(models.Model):
name = models.CharField(max_length=200,null=True) created = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.name
class Staff(models.Model):
name = models.CharField(max_length=200,null=True)
age = models.IntegerField()
department = models.ForeignKey(Department, on_delete=models.SET_NULL, null=True,blank=True)
worker = Staff.objects.get(worker_id=pk)form = StaffForm(instance=worker)
if request.method == 'POST': worker.name = request.POST.get('name')
worker.age = request.POST.get('age') worker.department = request.POST.get('department')
worker.save()
return redirect('home')
.
did you mean this?
Oxytocin
Hi
How can I call a function of parent record?
Actually calling a function of queryset that has one record
Oxytocin
How can I get all parents titles of a specific child
Input is an instance id
Output is all parents and grandparents titles of that from root to child
.
hi i have a model called dcotors
i've changed the default id to
id = models.AutoField(primary_key=True)
and everything was okay
but after that i want to manualy add the id so i changed that statement to this:
worker_id = models.CharField(max_length=10, validators=[RegexValidator(r'^\d{1,10}$')])
after thet the following error still eccours when i run the page :
Reverse for 'deleteDoctor' with arguments '('',)' not found. 1 pattern(s) tried: ['users/deleteDoctor/(?P<pk>[^/]+)/\\Z']
Darel
I want to create a video editor with Django ,anyone who has done this before to kindly give me some advice and resources to start with
Kene
Hi guys. How can I pass a field PK to a foreign key field of a Django form?
I have:
obj = obj.save(commit=False)
item['obj'] = obj
if item['image']:
request.FILES['item_image'].append(decoded_image_file)
else:
item['item_image'] = None
item_form = ItemForm(item, request.FILES)
But item_form.errors returns that obj is an invalid choice. I want to be able to pass the obj.id/pk since that is readily available after the initial save with commit=False.
rtg
hi! When we use Django-Allauth for example with Google API, we get user data. Which data? Where can i see all data? Thank you? probably i need to get more data using "one to one" but i don´t know all data i get with google API in django.
Junior
Hi, I've been struggling with adding a background image in Django template using the background-image= url ('{% static 'myimage.png' %}'), it's not displaying the image when I run the server. Anything I'm missing?
rtg
try this.... background-image= url ('{% static "myimage.png" %}')
rtg
(i am not sure)
rtg
background-image:url ('{% static 'myimage.png' %}')
rtg
background-image: url ('{% static "myimage.png" %}')
Junior
rtg
style="background-image: url('{% static 'myimage.png' %}');
rtg
(it is correct, because i am using this code)
rtg
is your static settings ok?
rtg
try this:
rtg
<div height="500px" style="background-image: url('{% static 'myimage.png' %}');"></div>
Junior
Or do you have any idea of what's responsible for displaying background images. Maybe I can check my settings if it's really available
rtg
if you can show other images or css and js files, your static setting is ok
rtg
try this: <img src="{% static 'myimage.png' %}">
rtg
can you see the image?
Junior
Yeah, displaying images is okay, no problem with that. But using it as background is not working
rtg
ok
rtg
your static setting is ok
Charly
Junior
Of course, I searched, googled, and I see I'm not the only one facing the problem, but I still get no solution. I've typed the codes repeatedly, and nothing works
Junior
Charly
rtg
<div height="500px" style="background-image: url('{% static 'myimage.png' %}'); width:100%;"></div>
Junior
It's what I've tried repeatedly,
rtg
sometimes the image is very big and you only see the white part of the photo. But i am not sure.
Junior
rtg
Show your code with pastebin
rtg
follow Charly steps with browser developer tools... you can see in the console errors...
Junior
rtg
I have a dude: If i use Google API with django-allauth for user register and login. It is excellent. How can i see all user info that Google API gets? 🤔 thank you!
Anonymous
hi. what is the solution for "product multi variant" ?
Anonymous
Doragonsureiyā
how to send image in group! 😂
Rule 5️⃣: To share code or error tracebacks, use an online pasting service like:
- https://dpaste.org
- https://linkode.org
- https://hastebin.com
- https://bin.kv2.dev
If you posted a wall of text, go back and delete it.
Fawzul
The error?
I cannot delete the item in the migration if i delete it says error
python
Qureshi
How to making website django please