Cool
How can build a song download website in django??
Anonymous
Anonymous
Code9
Anonymous
Good evening people, someone can help please with setting up telegram bot on django, maybe somebody already done it?
Anonymous
>>> django-admin startproject partners
>>> python3 manage.py startapp partnersbot
/partners/settings.py
INSTALLED_APPS = [
'partnersbot.apps.PartnersbotConfig',
]
/partnersbot/urls.py
urlpatterns = [
path('', csrf_exempt(views.webhooks), name='webhooks')
]
/partnersbot/views.py
from partnersbot.config import bot
from partnersbot.config import dis
def webhooks(request, bot_token):
try:
upd = Update.de_json(json.loads(request.body.decode("utf-8")), bot)
except Exception as e:
return JsonResponse({})
dis.process_update(upd)
return JsonResponse({}, status=200)
Anonymous
bot does not work(
Django Bot
>> Links
- Detailed Error Emails For Django In Production Mode – vilimblog
- 使用 Nginx 和 Gunicorn 部署 Django 博客_Django博客教程_追梦人物的博客
inchidi
inchidi
btw consider edit your message since its contain your bot token 🌐
inchidi
hmm i never see things inside ptb but afaik ptb already handle its own http connection
inchidi
inchidi
Anonymous
ty for some advices)
Anonymous
webhooks() missing 1 required positional argument: 'bot_token'
inchidi
inchidi
inchidi
Anonymous
@Inchidi thank you, everything becomes clearer, couple of hours and it will work
Django Bot
>> Links
- Model Mommy: Smart fixtures for better tests — Model Mommy 1.2.1 documentat
Anonymous
How can learn django ?
inchidi
Django Bot
>> Blogs
- Web Development Tutorial: PHP vs. Python & Django
Maz
hi guys, ran into a small issue during running my dev server...
Maz
https://dpaste.de/T2Ww
Maz
that's the error
Maz
this is my views.py
Maz
what does NoneType mean? This code was running fine just yesterday
inchidi
looks like this is your models.py not your views.py
Maz
oh yeah...lemme do the views.py
Maz
it's the home view that says NoneType...
Maz
https://dpaste.de/4LSo
Maz
the views.py
Maz
meaning...
inchidi
means Staff.objects.get(user=request.user).school==None there
Maz
but in the models file, i havent explicitly declared Null=True
Maz
oh yeah...seen it...from the Staff model
Maz
lemme change it and will let you know if it works good
inchidi
you will get conflict on migration btw
Maz
you will get conflict on migration btw
You are trying to change the nullable field 'school' on staff to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Ignore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)
3) Quit, and let me add a default in models.py
Select an option:
Maz
yes i have actually
inchidi
do you care with your current data?
Maz
haha, yes i do man
Maz
but how come this error pops up now? it was running fine a f
inchidi
then run this in shell:
for staff in Staff.objects.filter(school_isnull=True):
print(staff.id, staff.school)
inchidi
tell me estimation of printed id
inchidi
or Staff.objects.filter(school_isnull=True).count() should be enough
inchidi
Maz
failed 😅
Maz
https://dpaste.de/h1Yx
inchidi
inchidi
your task now is make Staff.objects.filter(school_isnull=True).count() == 0
Maz
I know...but i dont want to tamper with default values and nulls since it might corrupt my data...
Maz
question is...why is it throwing this error now? it worked fine before
inchidi
the problem is some Staff data have null value
Maz
inchidi
Maz
so should i manually go into the db and fill in the null value fields to avoid messing with the command line
inchidi
Maz
inchidi
for staff in Staff.objects.filter(school_isnull=True):
staff.school = School.objects.get(id=1) # just an example, id should be different for each staff
staff.save()
via shell, all you need to do is assign staff.school for each iteration
inchidi
well, i thought you have thousand important data -_-
inchidi
if thats all your data, running Staff.objects.get(id=10).delete() should fix everything then
Maz
okay
Maz
i've deleted that one record but i still get a RelatedObject DoesNotExist error
Maz
RelatedObjectDoesNotExist at /schoolbus/
Staff has no school.
Request Method: GET
Request URL: http://127.0.0.1:8000/schoolbus/
Django Version: 1.11
Exception Type: RelatedObjectDoesNotExist
Exception Value:
Staff has no school.
Exception Location: /home/alex/schoolbus_work/env/local/lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py in get, line 194
Python Executable: /home/alex/schoolbus_work/env/bin/python2
Maz
haha, it's always the ORM that messes me up though
Maz
Oh so that's where the problem is
Maz
Of course I have duplicate school ids, because 2 staff members can work at same school