#web-development
2 messages · Page 86 of 1
does automating a post actually count as scraping?
@slow rampart it's none of my business to ask whether it's one post or several but usually possibilities are limitless, you can do a lot cool shyt by scraping a website but I am sure if you try to scrap reddit, their rate-limit will kick you
Iirc, there is an api which you can use to retrieve information from subs, unless they deprecated it / removed it
praw?
Yeah
that only works for getting posts not making them afaik
the thing is, OP wants to send stuff out
im using it on a discord bot im making
I’m looking at the reddit api, and it seems you can post comments and create threads and such
why would you want do use that
i dont think im allowed to discuss things like that here since i believe its against reddit tos, but i will not be using it maliciously
its supposed to automate posts though, and it will have a delay so its not spamming
I wouldn't scrape reddit, there are many better websites for doing that
just to help automate a bit
Reddit’s /api/submit is the endpoint. Don’t know what that correlates to in praw
anyone experienced with postgress and heroku think they can help me real quick
yeah shoot @hallow jacinth
I am not sure why when I run my server that the postgress db isn't getting updated with my db models
I tried getting rid of my migrataions folder, rocommended earlier, but that didn't seem to help the problem
hmmm let me check on the site real quick again
since I am using flask do you mean the config.py? Also, it seems to be set up properly. It at least registers locally
@versed python
I don't know how to configure flask
but I am sure there must be some settings for it too
look up how to use postgres with flask @hallow jacinth
search on google
okay ill try that
https://github.com/arcticlimer/flaskquotes
made with flask 🙂
Now you can try it by going at localhost in your browser:
localhost:5000
change it to http://localhost:5000/ in Your README. nice project, looks good. @native tide
he doesn't need to do that @versed python
well it is just a bit more verbose and thus looks more professional.
either way both will work so no harm in keeping it the way it is
thanks 🙂
I am trying to add a dropdown list from bootstrap, as is demonstrated here:
https://getbootstrap.com/docs/4.5/components/forms/#form-controls
I added it to another form, but when the form is submitted, the value for logChannel isnt provided. Help?
<form method="POST">
<label for="prefix">Prefix:</label>
<input type="text" id="prefix" name="prefix" value="{{prefix}}" size=6 maxlength=8 required><br><br>
<div class="form-group">
<label for="exampleFormControlSelect1">Example select</label>
<select class="form-control" id="exampleFormControlSelect1">
{{channelOptions}}
</select>
</div>
<button type="submit" class="btn btn-primary">Save Changes</button>
</form>
@ me when answering, please.
hello again. I was working my project and encountered a "id does not exist" error. Any suggestions?
from what I remember I wrote the db.relationship lines correct, but maybe not
@versed python wdym by which view
@topaz finch you must have a views.py which will be using the html template you sent.
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
paste it here ^
howdy friends, I have a custom user
class User(AbstractUser):
bot_admin = models.BooleanField(default=False)
and I would like to add the field "bot_admin" to the admin panel. I am using
class CustomUserAdmin(UserAdmin):
add_fieldsets = UserAdmin.add_fieldsets + (
(
None,
{
"fields": ("bot_admin",),
},
),
)
admin.site.register(User, CustomUserAdmin)
but this does not affect the admin page at all it appears
oof, I need to stop posting here, I always solve these so fast after posting haha, I guess "add_fieldsets" is no longer a thing... or maybe never
@versed python after 2 hours of searching, I happened to find the answer when I gave up, of course. I just had to set the name attribute.
@topaz finch congrats!
@acoustic oyster sometimes its the typing out the problem that results in the answer. I wouldn't feel bad about it.
haha, ty. Who wouldve thought the solution was to read the docs 😅
Hello. How do I prevent flask from sending html back as response instead of just status codes
admin.site.register(User, CustomUserAdmin)```
@acoustic oyster cool use of decorators xD
flexes the iron fist into Friendo-bot
haha
Anyone know of a good guide to seamlessly deploy my Flask app to production on a VPS?
Oh dang that's a bulky video
he covers a lot of the basics, including setting up the server from scratch
if this is too much, linode and I think digital ocean have their own guides as well
Yeah I'll be using DigitalOcean actually
Also if I want to run 2 flask apps on the same VPS
I should essentially do the same steps and just change the port number it runs on?
well, I personally use apache with virtual hosts. And I also use django, there should be Flask docs for official methods to serve the application
Also if I want to run 2 flask apps on the same VPS
@cold socket best solution: docker, docker-compose, traefik.
Decent alternative:nginxas a reverse proxy forgunicorn/uwsgiorapachewithmod_wsgiand virtual hosts.
@honest dock is this something like WTF forms? Do you need to iterate through your form file with something like {% for field in form if field.widget.input_type != 'hidden' %} to make each field show up? Also what route is your form sending the POST request to?
Hay guys! is someone acquainted with **Django **and Fixtures?
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
write here @primal kernel
So I execute the next command:
python .\manage.py loaddata .\rules\fixtures\rules.json
But I get the next error:
AttributeError: Problem installing fixture 'C:\Users\Ángel - Trabajo\Documents\AVC.\rules\fixtures\rules.json': 'NoneType' object has no attribute 'id'
Oh wow i'm sorry wait
well it looks like there was an issue exporting the data
if you look at the fixture itself, every object has pk: null
I read that if you write pk: null it gets an autoincremental number
no
it gets that when django does the database handling for you
since you're loading data manually, you need to absolutely correct and valid fixtures, otherwise it won't work
the simplest way to fix this is just add pk=1, pk=2 as so on
show me the error
Same: AttributeError: Problem installing fixture 'C:\Users\Ángel - Trabajo\Documents\AVC.\rules\fixtures\rules.json': 'NoneType' object has no attribute 'id'
The tables are created but no data inside
i mean is there already data for the models License and the other one?
The tables are created but no data inside
@primal kernel yep that's the problem
No, sorry, in license and profile there is only one row with ID: 1
you see, in your fixtures, under the fields object, you are referencing to license: 1. but that doesn't exist and your database doesn't know what to do
The empty table is Rule
No, sorry, in license and profile there is only one row with ID: 1
@primal kernel well that complicates things
maybe just delete the database and start over again?
Yeah I will try
or you could wait will someone else comes along and has a better solution
Here
mostly deleting the db does the trick
do you have an element for profile too?
Yeah for both
It's ok @versed python i'll investigate, thank you so much
Yeah good idea I will try
i was trying to deploy my flask app to heroku
but it throws a bunch of errors
is there anything wrong in my procfile
but it throws a bunch of errors
@barren stratus It failed tobind()to the socket because it's already in use.
That means something is already listening on the port; either another copy of your app or something else.
nginx, gunicorn, etc.
Do you guys like Djoser in Django or it is rather crap ?
Do you guys like Djoser in Django or it is rather crap ?
@native tide you know what's crap? your racist display picture.
I use numbers. You can always set the precision on the client-side.
If you just display them, it doesn't really matter. If you do calculations in JS, floating-point makes it easier.
(Assuming it is safe to ignore floating-point errors)
Normally those are small enough to be negligible if you just display prices.
How can i make a model that can have multiple Charfields?
Django?
class BlogPost(models.Model):
title = models.CharField()
text = models.CharField()
Oh yes i mean in Django
And if I beforehand do not know how many Charfields i want
SQL is schema-first, so you need to define your tables and fields before you insert data, i.e. add those fields.
If you want something dynamic, consider using a JSONField and storing the fields in there.
And if I beforehand do not know how many Charfields i want
@sullen basalt you can always make changes to your model later on
I mean, the user should be able to click a button to get another field and I want all of the fields to be added to the database
But i do not understand how i should handle this with a Model
soo perhaps?
class Example(models.Model):
name = models.CharField(max_length=255)
fields = JSONField()
Yup. You'll have to handle the input yourself though.
So i can put the fields that the user adds all into JSONField
@sullen basalt you should actually define a second model which will store all the text fields that you want. this will enable you to have a variable number of CharFields associated with a model very easily.
class ExamplePerson(models.Model):
name = models.TextField()
class ExamplePersonPhoneNumber(models.Model):
example_person = models.ForeignKey(ExamplePerson, on_delete=models.CASCADE)
phone_number = models.TextField()
as you can see, you can associate as many phone numbers to a person as you like
I think this is the way django docs suggest too. Or maybe i just read a Stackoverflow answer saying it is. Either way this is the best solution imo.
#View
def edit_profile_screen_view(request):
if request.POST:
form = UpdateProfileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
else:
profile = Profile.objects.get(user= request.user)
form = UpdateProfileForm()
context['form'] = form
return render(request, 'Profile/edit_profile.html', context)
#Form:
class UpdateProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = ('link', 'description', 'picture')
#Model
class Profile(models.Model):
class Meta:
db_table = 'Profile'
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
link = models.TextField(db_column='link', default='', blank=True)
picture = models.ImageField(db_column='picture', upload_to=upload_location, null=True, blank=True)
description = models.TextField(db_column='description', default='', blank=True)
This gives me this error: NOT NULL constraint failed: Profile.user_id but I don't know how to fix it. Anyone know how?
@honest dock you're not really assigning a user to the profile object
to fix this, type these lines before form.save()
@versed python yes, and it frustrates me that I don't know how. I tried form.user = request.user
instance = form.save (commit=False)
instance.user = request.user
instance.save()
and then delete the form.save() statement
form.user = request.user is wrong since the form is not the Profile, it doesn't have a user attribute associated with it
Can you explain it for me?
@honest dock yeah
I see
line 1) form.save(commit=False) gives you the Profile object you are gonna save. commit=False prevents django from actually saving the object to database and thus error is raised
line2) the instance (which is actually a Profile object) gets the currently logged in user associated with its user attribute
line 3) object saved to database :D
I see
I'll give a try right now, thank you!
It's working
But!
It hasn't updated the profile, instead, it created a new one
Yes
oh i get it
From a generic view, what would the best way be to execute code when the view is requested?
I was thinking of putting it in the Setup()
Override it and call the super method
@solar ridge you could also override the get method
thanks, I solved it with a override of dispatch
How do you get cards to show “side by side” in Django? Without the text going on the side too?
Is there a special decorator to use for running code after flask app closes?
How can i pass app argument to a class if that doesn't have the .init_app method?
@frozen python you mean bootstrap cards?
maybe you can add it in the constructor directly @weary dragon
and if i do that how i can import it?
Import what 😄
@versed python yes, but it’s Django, it’s cycling through my info and placing it in. It’s showing side by side with my different info. I have a picture, paragraph and name.
@frozen python as far as ik you need to add a card body class to the actual text contained inside the card
@native tide i have now a import error, i don't think if i put a variable into a function i can import it
same thing
my function look like this ```py
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(config_class)
db.init_app(app)
login_manager.init_app(app)
mail.init_app(app)
migrate.init_app(app, db)
discord_oauth = DiscordOAuth2Session(app)
from flaskblog.users.routes import users
app.register_blueprint(users)
from flaskblog.posts.routes import posts
app.register_blueprint(posts)
from flaskblog.main.routes import main
app.register_blueprint(main)
from flaskblog.errors.handlers import errors
app.register_blueprint(errors)
return app```
and when i try to import discord_oauth i get a import error
@versed python ok, I’m still messing around with card pictures too, there not lining right.
class Book(models.Model):
STATUS = (
(1, _('Available to borrow')),
(2, _('Borrowed by someone')),
(3, _('Archived - not available anymore')),
)
[...]
status = models.PositiveSmallIntegerField(
choices=STATUS,
default=1,
)
if you have a model like that, how can you add functionality for the user to create a new status to the choice list. one that doesnt exist already on the list. ie. a 4th status
@frozen python go to the bootstrap website, they have a good guide on cards along with images
@mental veldt should probably create a new model for that
if you have a model like that, how can you add functionality for the user to create a new status to the choice list. one that doesnt exist already on the list. ie. a 4th status
@mental veldt you can't, really (AFAIK). Add anOtherstatus and accept an optionalother_reasontext field.
@mental veldt should probably create a new model for that
@versed python how??
pm@mental veldt
@mental veldt you can't, really (AFAIK). Add an
Otherstatus and accept an optionalother_reasontext field.
@lethal orbit oh ok👍
@mental veldt no no it can be done
I guess you could with another model and a relation.
And get the choices from the other table...
@lethal orbit yep, and should be pretty easy too
@versed python I use Bootstrap all the time, just not with where the content is cycled through, so it’s just one card, that’s the template
class BookStatus(models.Model):
status = models.CharField()
class Book(models.Model):
# other stuff
book_status = models.ForeignKey(BookStatus, on_delete=models.SetNull)
@mental veldt
@frozen python still the html itself will be governed by bootstrap classes you use and you need to use a class to adjust the card image
class BookStatus(models.Model):
status = models.CharField()
class Book(models.Model):
# other stuff
book_status = models.ForeignKey(BookStatus, on_delete=models.SetNull)
@versed python ok let me try it out. Thank you
you're welcome
Django.
How do I show specific data to each group?
For example, I have this code:
{% for i in user.information.all %}
<tr>
<td><a class="btn btn-sm btn-info" href="{% url 'info-page' i.id %}">View</a></td>
<td>{{i.topic}}</td>
<td>{{i.full_name}}</td>
</tr>
{% endfor %}
Now I want to do the same thing just for groups and not specific users, anyone has an idea?
@versed python I just tried it, it’s still in a stacked
i am not that good at bootstrap so I don't think I can help further sorry @frozen python
anyone really good with curl?
anyone really good with curl?
@icy frigate https://dontasktoask.com/
my git repo has 4800 objecys 0.0 how do i trim it down. I have a .gitignore, but maybe i added it too late nd some of those packages are still included
if you know what files you added by mistake, you can do git rm --cached file_path_or_folder
you better ask this question in #tools-and-devops @hallow jacinth
Heey guys!
People from #internals-and-peps send me over here to ask hahaha
How u guys doing?
Did Someone here worked with uwsgi?
I'm facing some issues here.. :(
Trying to deploy a project with multiple threads and Flask application. But I can't get it to work...
I want the threads that i'm creating only in main process (right now it is beeing replied on every process), and I want flask (and just flask) in multiple processes... Is this possible at all?
I’m creating a button to click to run a terminal command ....but I don’t think it’s registering right.
This is in VSCode
Hey there! I had something to ask! I'm asked to make a responsive design of a desktop-version website. Will it be okay if I display : none the desktop version and code the mobile-version separately and keep both the codes in a single file so that each of them load according to the screen size?
@frozen python is the file named tasks.json?
@versed python it’s settings.json
@frozen python https://code.visualstudio.com/docs/editor/tasks
@vague ibex it'll be okay but there are plenty of frameworks out there which you can use to have a single code base. one example is bootstrap
should i be using apache instead of iis on my windows laptop to dev a web api that will be hosted on an ubuntu server?
@vague ibex it'll be okay but there are plenty of frameworks out there which you can use to have a single code base. one example is bootstrap
@versed python alright ty! 😄
Just wanted to use plain html css js code tbh lol
Bootstrap is easy and short but it complicates things
@versed python
https://discordapp.com/channels/267624335836053506/366673702533988363/753249981845995651
Still need help with that. :/
@native tide whym about groups?
Hey guys, do you know how after a form submission you can refresh the page?
Nevermind! Solved with redirect(url_for('function')) and adding returns on every if/else statement in the route 😄

@versed python no, when I hit the button it does that. When I type in everything manually, it works
@frozen python that's weird never really happened to me
@versed python do I need to add something like ${}?
Hi, as you might know there are functions for a website to find out if the website is in focus. Does any1 know some test website that exists to test if it is in focus or not? I know it is something easy to program, but I am not at my dev environment rn.
A friend made me curious about what happens if you have multiple browser windows open (not tabs), for example with 2 monitors each having their browser windows.
@versed python what other commands do you have? What does a layout of code look like?
is there a certain way to handle multiple forms in one page with FLASK??
you can only submit one form at a time
by default
@hoary sable unless you do js stuff
plus by default submitting forms reloads the page
unless you use js to submit
oh ok so that's why i'm stuck for hours
is there a way to solve the problem ??
i have a page with a search input that display users and then i added radio buttons to vote for a user which means it's 2 forms in a page
I'm having trouble reading external json files in Django
It is saying directory does not exist
Anyone have experience?
@warped timber any ideas ??
So I'm having trouble setting the path to my file
can someone send a article or vid of where i can learn about DOM & events
check out a video about Jquery @native tide
here hop in help chat and explain what you are trying to do @native tide
I'm in code/help @native tide
Is a good way of learning making small projects to practice specific skills?
@limber laurel absolutely
For example if I would want to make a more secure app maybe I should make a seperate sort of blog app maybe with nothin fancy on other things but higher security
i just need help with what dom & objects is
did u use solo leaRN?
dom
only DOM
no js
im learning js
check freecodecamp
lmao
I want to detect the changes in my text editor Live for example if I added Heading with the Keyphrase Improve Grammar the messages on right will be marked as completed.
See these pictures for detail
where can i learn ES6?
would anyone be able to help me with some Flask-SQLAlchemy related issues?
I FREAKING FIXED IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
also, what issue are you having?
@dense bear
well, I've got a fairly functional small app, and I'm trying to add a new table and form into the mix. The error I'm getting is that there are too many foreign keys associated with the new table though
I think I may not have a proper understanding of how to set the relationships up
hmm, maybe you are using foreign keys, when you are intending to use primary keys
I am not 100% sure why you would be getting that error though. might have to do with the way you set up your relational model
@hallow jacinth can i ask u i'm having issue with my flask website ??
sure I can try to help @hoary sable
it says specifically that I may have intended to use a primary join, though I didn't think I needed one
if you take a help room up and show me what your models look like I may be able to help better
i have a page with a search input that display users by name and put them in a card and then i added radio buttons for each card to vote for a user which means it's 2 forms in a page but the voting system is not working is it something from flask itself ??? @hallow jacinth
i'm having same issue like this guy https://www.reddit.com/r/flask/comments/1vziqt/flaskwtf_multiple_forms_on_page_headache/
but i'm not using wtforms
oh uhhh, those seem occupied. I'm not sure how to go about making a new room. still new to this server
I think I figured it out
@hallow jacinth take your time and thank you do u want me to send u my code . i didn't send it here because some ppl don't like to see code taking space in the chat
shoot I think I reserved a room but I don't know where the room went. I thought it was named help-sodium
yeah, @hoary sable take a help room and let me see what your .html and route.py look like
ok
@hoary sable you can make them submit to 2 different endpoints
anyone have an idea why my db connection times out everytime a new row is added to a specific table? the connection times out, but when I refresh the route it sends duplicate messages ahaha
(postgress, heroku, flask issue)
@warped timber problem solved i forgot a line that render the page before the second if u can check more in help-oxygen guys noticed it there
How do you create a Alias in VSC? I just got a tip to do that as a shortcut for runserver
idk, I use .bat or .sh for making my shortcuts
Should I stick to django template system or integrate react ?
I have moved away from django templates and now use react. I highly recommend it, it allows for much more flexibility, and creates much more interesting stuff imo
I would personally not use templates for any very serious project nowadays simply because react makes things so much more interesting and offers functionality that is essential on many projects
U also use redux or is context api?
I agree 2, react's better 4 serious web dev
An django as back end
I just use plain 'ol react with axios to make api calls for DRF backend, I am moving to graphql though as well
Gr8, I love functional components and hooks. u ever seen the YT channel DevEd ?
ohh, I dont think so. What do they do?
oh, very nice. I have never seen any of his videos.
I do not do a ton of front end xD I learned react mostly from docs and examples. I watched a quick video though.
but ty, I will have to remember these
I don't do front end that much but I'm currently learning it to get a job with my back end skills
I hate css
But have to study it
React docs are well documented
I like them
Not sure if this is the right chat to ask this. I am trying to use Kivy with Pycharm but I can't get a preview of my app no matter what I do. I have kivy and the dependencies installed but all I get is console output. No image or label. Am I missing a simple fix?
ok I will do that thank you
@versed python not really, I created a bash_profile and a .bashrc file, but it’s not executing my commands
@frozen python alright tell me what exactly you want? because as far as I know, bashrc and bash profile files are not needed
@versed python you can create shortcuts to create execute a terminal command
so in your current workspace create a folder called .vscode and a file inside tasks.json
then add the tasks you want to in that file
i sent you the website, just copy paste some default boilerplate code from there and you can extend it later @frozen python
also as far ik, you don't have to even touch the bashrc and bash_profile files
@versed python I’ve tried that, but it didn’t work in the tasks. That’s what’s not executing right
maybe you could chain commands? like
source venv/bin/activate; python manage.py runserver@frozen python
&&?
@versed python
yeah
and as the other person suggested, you can also try replacing ; with &&. try out both
@versed python should I only have one? Is it laid out right?
if you mean just one task, yeah that should do the trick
if you mean && then no, you need both
a single & will send the process to background and you'll be left without an activated virtual environment @frozen python
@versed python I just typed in the snippet and it didn’t work
what error does it give?
@native tide now there’s no errors but I’ll try it again
@native tide is says “ZSH: command not found”
you're pinging the wrong person lol
why don't you change your default shell to bash?
ctrl+shift+p -> change default shell
@frozen python
I got it to work.... I just created “tasks” in VSC.
yay
**Django: ** (pls @me)
I'm successfully able to create database entrys out of ModelForms that are filled based on the fields provided in the form.
But how can i additionally pass the active user to the form.save() ?
(I want that every time a user creates a chracter this character gets assigned to him.) I have a correspending field set up:
class PlayerCharacter(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="playercharacter", null=True)
...
def charactercreation(request):
form = CharacterCreationForm(request.POST or None)
if form.is_valid():
form.save()
return redirect ("main:home")
class CharacterCreationForm(ModelForm):
class Meta:
model = PlayerCharacter
fields = {'pc_name', 'pc_age', 'pc_race', 'pc_class', 'pc_armor','pc_talent',
'pc_attrCon', 'pc_attrStr', 'pc_attrDex', 'pc_attrMag', 'pc_attrSlh', 'pc_attrRfx', 'pc_attrLck', 'pc_attrPct' }
def __init__(self, *args, **kwargs):
super(CharacterCreationForm, self).__init__(*args, **kwargs)
pass
@onyx crane you'll have to override the savemethod instead of __init__ method
class CharacterCreationForm(ModelForm):
def save(self, user):
# do stuff with user
return super().save()
class Meta:
# as above
```
urgh i remember reading something that it can't or shouldnt be overriden or smth
- what exactly do i do with the user ?
i couldnt find any doc about how the .save method actually works
Hey guys, does anyone have experience with github pages?
i've followed the documentation to the T and still can't get my custom domain to work
my github looks like:
while my domain site godaddy looks like:
@versed python sorry I was pinging you!
@onyx crane what do you need to do?
def save(self, user):
self.owner = user
return super(CharacterCreationForm, self).save()
This didn't work.
Do i need to define the 'owner' field in fields to make it a part of the form ?
just tell me what you are trying to do, i feel like you are solving the problem incorrectly @onyx crane
oh.
well im trying to fill in the owner field of my model with the user who submitted the form, without using a form field where the user selects himself
if form.is_valid():
character = form.save(commit=False)
character.owner = request.user
character.save()
this goes into your views.py @onyx crane
TypeError at /charactercreation
save() got an unexpected keyword argument 'commit'
did you remove the save method from the form? @onyx crane
Hello can someone help me figure out how to query this data so its useable? I have this section in a flask route
if g.user:
user_likes = g.user.likes
print(user_likes)
the print statement is returning something that looks like
[<GovMembers O000172>, <GovMembers C001093>, <GovMembers C001091>]
I need the last bit, in this case the C001093 id part only so I can use it in my jinja template. How can i return just the ids?
For reference my 'Likes' model only contains an id, user_id, and item_id which would be the id number I'm looking for
@onyx crane np
Hello can someone help me figure out how to query this data so its useable? I have this section in a flask route
if g.user: user_likes = g.user.likes print(user_likes)the print statement is returning something that looks like
[<GovMembers O000172>, <GovMembers C001093>, <GovMembers C001091>]I need the last bit, in this case the C001093 id part only so I can use it in my jinja template. How can i return just the ids?
For reference my 'Likes' model only contains an id, user_id, and item_id which would be the id number I'm looking for
@zealous cloudlistcomprehension
[like.id for like in g.user.likes]
more efficient: g.user.likes.values_list('id') (this should work)
I was about to get a JetBrains subscription, but after learning how to use “Tasks” in VSC, I think I’m sticking with VSC
Does anyone use AWS Lambda? I'm wondering if there is an environment variable available that I could inject into templates. So that if I have two versions of a website say, I could have the stack name or env name displayed at the bottom of the page so that I can tell at glance which one I'm looking at?
Would it be considered bad practice to download bootstrap and strip what I need from it for my own css?
depends on what License they use, but it should be generally fine
MIT copyright Twitter 2018. I know the copyright wasn’t needed but I found it funny lol.
So yeah legally I’m okay.
pretty much
can i ask a html css related question
can someone please help me , i want to add a link inside a para like
<p style="css stuff"> blah blah blah <a href="link.com">text</a></p>
but this turns the entire para into a link and somehow the page code isnt what i wrote it says something <a class="icon"...> something instead of my <p> tag in the inspect element of the page
i am using vs code with live server
so no one can help me

?
sorry i couldnt help
thanks np
@lean saddle are you sure you're clicking inspect element on the right element?
yes
Make a style tag with the css stuff or a css file and then use <a class=“css class”>
because what you have written is absolutely correct and should technically work fine
i stil dont get it wait let me show u
@zealous cloud
listcomprehension
@vestal hound Thank you that did the trick!
That works but can get messy if you are making a style for almost everything within the tags.
Look at w3school man at example.
Just a heads up, please make sure that you are aware that piracy is a crime and is also an immoral thing to do, so I suggest that you buy games rather than finding the cracks' cause believe it or not, the chance of a crack being a trojan or virus is quite high, so here is a friendly advice, go to your local shop and buy a DVD or CD. It's quite cheap. And please install some antivirus like <a href="https://www.malwarebytes.com/mwb-download/" style="color:rgb(24, 117, 160);text-decoration: underline;"> MalwayreBytes</a></p> ```
and here is what shows in the inspect element section
Just a heads up, please make sure that you are aware that piracy is a crime and is also an immoral thing to do, so I suggest that you buy games rather than finding the cracks' cause believe it or not, the chance of a crack being a trojan or virus is quite high, so here is a friendly advice, go to your local shop and buy a DVD or CD. It's quite cheap. And please install some antivirus like </a> ```
are you using normal HTML or some frontend framework?
<!DOCTYPE html>
I think you should be scared, it looks like your computer has gained intelligence
<!DOCTYPE html>
@lean saddle that's normal HTML
this should not be happening
that is what i thought
the browser doesn't randomly make changes to your code
are you sure you're opening the correct file?
could this be live server
idts
in vs code
I highly doubt it
why don't you check and open the file in a normal broswer like google chrome?
yeah do that
guys anyone her can help for somthing in django
can i ask again
guys anyone her can help for somthing in django
@mystic wyvern don't ask to ask
just ask.
if you don't reply within an hour, i am gonna assume your computer has indeed gained intelligence and killed you
and is out for human blood
ok
@mystic wyvern don't ask to ask
@vestal hound ok,(:
😅
the for loop in file(html) dosen't work with me why?
what?
what are you writing in code @mystic wyvern
you're going to need to give a lot more details
{% for Board in bored %}
{{Board.name }}
{% endfor %}
...what is bored
@versed python sir thanks so much, its my browser,firefox is glitching
yay you're not dead!
tell that to my console i typed apt-get update && apt-get upgrade and i have been regretting it for 4 hours
...what is
bored
@vestal hound The thing that will bring me back from databases
Hi
ok
Can anyone tell me what is flask-caching extension actually used for?
from django.shortcuts import render
from django.http import HttpResponse
from .models import Board
def home(request):
bored = Board.objects.all()
return render(request,'html.html',{'board':bored})
can you remove name and just write {{ Board }}
ok
wait
i get it
you have misspelled board in your views
both the spellings should be same
you have board and bored instead
you need to write {% for Board in board %} now
yeah please do
ok in thes line what should i write {{Board.name }}?
didn't work
omg thanks
its workkkkkkkkkkkkkkkkkkkkk
no change required
@versed python thx man
@versed python REALLY THANKS i I tried to fix it for 2 day
I have a sanic webserver running on port 8000, how can I make it use nginx (where my ssl cert is)?
Each time I try and edit the config to use port 8000 it says the sanic server is already using it
Please ping me
@tropic lance you should bind your sanic server on ankther port, or even better don’t expose it
@versed python REALLY THANKS i I tried to fix it for 2 day
@mystic wyvern yeah np
Do i need any external security for my web app built with "Django and Angular"?
If yes...How?
Hi, Can anyone tell me what is flask-caching extension actually used for?
@hot kraken security from what?
i am taking a result from a form in html and printing it. , now the result is being replaced.. when i give the data again i need to give the result on a new line..any idea?
to make it in different line?
ping me if anyone can help
Do i need any external security for my web app built with "Django and Angular"?
@hot kraken firewall, protect your DB, make sure to handle CSRF/XSS ....
Django does take care of a lot of it OOTB
Hello , where can I ask questions about git?
#tools-and-devops would be the right place 
@versed python
From unauthuroized hackers or bots
#tools-and-devops @hot kraken
Does anyone know where I could find a junior developer, who wants to create a front-end to add to their portfolio? For the past 3 weeks, I've been working on a e-commerce store like Sellfy. For creative people to sell their digital content/subscriptions. The only problem is I suck at front-end, and have no plans to be a front-end developer. I have 70% of the back-end done, but the front looks pretty shit
@past cipher if you're willing to pay the front-end dev, you can try fiverr
right now it isn't paid. Hoping to find someone who wants to add something to their portfolio to show potential employers. If I do end up paying, I will hire a non junior
tbh ngl I couldve worked but your profile pic scares me
lol
I get this all the time
when i signed up for Discord, I googled "avatar"
and chose the first one 🤣
When I make a list of webelements using driver.find_elements_by_css_selector('div[role="row"]'), how is the elements of the list like?
I setup a login process using DRF for my Vue.js front-end. But any tutorial I read related to authentication ends at sending the token. I'm just not able to find how to use that token to actually authenticate user requests.
Any help or guide would be appreciated
@merry geode You using axios?
Right now I'm just trying it out on Postman
but you'll be using axios right?
Yes. So far I've used Axios for other things
Basically what I want is once the user is authenticated, when they call other APIs, I should be able to know
- That the user is authenticated
- The identity of the user from the authentication token
@merry geode have you heard about nuxtjs?
its basically vuejs on steroids
if you use that, i wrote a tutorial on how to setup and use user authentication with Nuxtjs and drf
If you can link me to it, that would be really great
However, right now my problem is on the Django side. I don't know how to consume the token in the requests after the user authentication is done
wdym?
once user authentication is done, you just need to make sure that you are sending the tokens from frontend and drf will take care of authentication itself
I'm looking for advice on what to write tests for in an application that essentially wraps a number of calls to other services in a single endpoint--obviously, testing my network connection is useless for the purpose of testing--is there anything beyond schema validation that people commonly do?
@merry geode this will help you https://dev.to/ignisda/setting-up-user-authentication-with-nuxtjs-and-django-rest-framework-part-1-5gji
once user authentication is done, you just need to make sure that you are sending the tokens from frontend and drf will take care of authentication itself
@versed python Exactly, this. How do I implement this in my other APIs
@merry geode read up 👆 on the tutorial, and if you need help after that, you know where to find me
also you'll not need to read part2
guys
i'm working in a project
we are having a problem with json encodings
that could be fixed adding 4 lines in the json package library
is that possible?
Should Django be used for styling? Or just make things functional?
....is Django good to focus on or is it mainly Python and let React and Vue be the true styling for front end?
anyone have any idea why everytime I try to post on my heroku hosted site, it says server error?
the logs points to something that doesn't quite make sense
Anyone good with selenium?
Why don't you just ask the question?
@woven gorge don't ask to ask
sry
You'll find out if you get a response or not.
@frozen spear template_name = 'core/AjaxTemplate.html'
Using selenium and actions to scroll to a specfic element on a webpage so i wouldnt get "Message: element click intercepted: Element <div id="loginButton" class="button">...</div> is not clickable at point (588, 650). Other element would receive the click: <div class="footer">...</div>" as an error.
driver.implicitly_wait(5)
login_button = driver.find_element_by_xpath('/html/body/div[2]/div/div/div/div/form/div[2]/div[1]/div')
action.move_to_element(login_button).perform()
login_button.click()
Still getting the same "not clickable at point (x,y) error.
Anyone know why actions is not moving to the particular element
@frozen python django can easily handle a good looking static website but most websites today are dynamic. That's why all these frameworks like Vue and React are getting famous.
You will be making more functional websites using a frontend framework, but will have a tradeoff of cost, learning curve and time and energy spent
@versed python did that
i tried every path
im doing that for a test
understading ajax
its not a big deal so ye
does it work?
@versed python cost as in it’s more time to do front end with React/vue? But tho, can I focus on Django for the Database part? Then other then that, just python in general?
@frozen python I meant the cost you need to hire devlopers to do your frontend. If it is a one man job, then it will take a lot of time yeah
you can focus on django and then move on to django rest framework and then to a frontend framework (Vuejs in my case). This is what I did but you can do it differently
@versed python what’s a difference between Django and a rest Framework?
thats a very broad question
Anyone have any idea why my flask app running on a rpi with nginx and gunicorn gives me a 403 error whenever I try to read a page that contains info from a database?
you will be better off looking at django rest framework website @frozen python
@versed python ok, I mean that as in Django with python vs ingeneral of a rest Framework
anyone have a website design which i can fo it myself?
anyone have a website design which i can fo it myself?
@wanton ridge what do you mean?
@vague ibex i mean i wanna create a website with html and css but i dont know how to design it maybe u know it
@vague ibex i mean i wanna create a website with html and css but i dont know how to design it maybe u know it
@wanton ridge Yea, I do. So, what is the specific topic you need help with?
@frozen python python can't be used for frontend, atleast not as extensively as Javascript
so if you want to make a good looking reactive website, you'll have to learn Javascript and then a framework like Vuejs or React
@vague ibex yes bro
@versed python I have been using them. I’ve been focusing more lately on Python/ Django, because I don’t like how vaug it is with styling..... not that radius, or color.... or wait yes that color 😂
@versed python I have been using them. I’ve been focusing more lately on Python/ Django, because I don’t like how vaug it is with styling..... not that radius, or color.... or wait yes that color 😂
@frozen python yeah I find Vuejs difficult too but I am slowly learning
@versed python vue has a bit of its “own” syntax. React uses more typical vanilla JS syntax. I prefer React vs Vue, but vue does have nice corner cutters
@frozen python from what I have read from their docs, vuejs is supposed to have an easier learning curve than React
@versed python yes, but I do prefer React because it has more support and add ons to use. I like Vue, but I think React has a more stable base
and a larger user base too. the industry prefers React due to its maturity. I understand where you are coming from. @frozen python
@versed python I like Vue tho, because once you get the hange of the “new” syntax, it’s nice. But there are things like Famer Motion and Styled Components I like with React, vue dosnt have
yeah ik nothing about them lol. Vue is growing in popularity quite quickly so that's a plus @frozen python
@versed python I’m at the point of that, I want to get a position, even if it’s a free position, just to gain the “work flow” experience and tips.
I'm definitely not at that point, especially with frontend since I am just starting out. Have you checked out codementor.com? @frozen python
@versed python no, I will! So to start out.... Traversy MEDIA, Dev-Ed, The Net Ninja, Corey Shaffer ... ARE GREAT!!! also Blondie Bytes
@versed python for YouTube channels to watch..... those are great
i am trying to design my own website for now, but yeah I have encountered some of these
i didn't know Corey was also involved with frontend @frozen python
@versed python no, I will! So to start out.... Traversy MEDIA, Dev-Ed, The Net Ninja, Corey Shaffer ... ARE GREAT!!! also Blondie Bytes
@frozen python Dev-ed is a legend
Hi, everyone.
Does anyone used social APIs with Python?
For instance, Instagram, Telegram, Facebook, OK, VK or Youtube?
If so, how we can identify if a user watched, liked or commented that video.
@vague ibex I'll check them out then, thanks. and thanks @frozen python too
Which language are you trying to learn ignisda?
@vague ibex hes very down time earth! Even if he makes a mistake, it’s nice to see how to fix it
@hoary bramble You can either do it through the website's API if available or create a bot that watches a users activity
Hello there
Also “codingentrepreneurs.com” YouTube channel
@cold socket Yes, I learned their APIs. For instance, Youtube V3 API. But there is no way to identify if user is liked some video. But a website vkmix.com is able to identify.
So in oAuth2 when someone is authenticate dhow do I deal with their AUTH and REFRESH keys while the are "on" the app so they don't collide with others
Also on “Skillshare.com” if you get stuck with JavaScript..., “KALOB TAUKIN” is great!
@cold socket How I can get allowance from Youtube to identify if user is liked or not?
I like how vue has it laid out with props, methods and that...: I’m messing up in React because I’ve been focusing on python
I’m mainly wanting to focus on, what’s the best “geared towards one thing”.... type of part of web design. Again, I don’t like the vague styling. I like how Django works.... but it’s still Jinja styling. But, I like possibilities of the back office right away. But, other than Datascience or machine learning... what’s a “need” of python that you don’t have to have college?
Hello how long does it take to learn django and where to start? Which skill level needed?

@quiet loom Django docs & youtube. Intermediate python skills, probably a little knowledge about how website works & html +css if you want to do frontend aswell.
Hi, everyone.
Does anyone used social APIs with Python?
For instance, Instagram, Telegram, Facebook, OK, VK or Youtube?
If so, how we can identify if a user watched, liked or commented that video.
How we can access user informations?
This is for an app to multiply likes of users like vkmix.com
@hoary bramble you would have to look at each individual API and see what they offer. I'm note sure if they offer user history, sounds like an invasion of privacy.
you would have to look at each individual API and see what they offer. I'm note sure if they offer user history, sounds like an invasion of privacy.
@near forge No it is not invasion. Just the app helps a user to multiply subscribers.
But for that I should check if user is watched and liked the video we give or subscribed to the channel we gave its link. Then if I know the user subscribes to a channel which we give, we give user some coins. For that coins they can buy subscribers.
I read but there is no way to do that.
But how VKmix.com identifies if user is liked a video or not.
I read full API docs.
But no way.
@vague ibex Vuejs
Yeah, I understand what you mean.
Thank you very much.
@glacial night What do you think?
Which one is easier to do first?
Identifying and getting user data from Instagram, telegram, facebook, vk, ok, tiktok or youtube?
how would I embed a variable that is a dictionary, from one .py file, into an html file
I'm doing a flask app
just trying to do a table essentially
@swift sky Are you using flask templates?
So you would need to pass the dictionary to the template in order to display it on the HTML file which can be achieved with
return render_template('template.html', dict_to_be_passed = dictName_in_py)
then in the template.html you can do
<h3>DICTIONARY: {{ dict_to_be_passed }}<h3>
and to display separate fields
<h3>DICTIONARY FIELD: {{ dict_to_be_passed['field_name'] }}<h3>
@swift sky
Does that make sense?
so i would need to make a separate template for the actual table file
No you can work with the template you currently have
ahh
Lets say you currently have
return render_template('index.html')
and index.html looks like
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
This is my HomePage
</body>
</html>
Then you can change it to
return render_template('index.html', dict = dict_in_py)
and index.html to
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
This is my HomePage
{{ dict }}
</body>
</html>
Does that makes sense?
Basically you are passing an argument to a function
and accessing that argument in the template
yes thank you
your guidance helped me see that i actually need to edit some code before i even work on importing
the scope of the dict im trying to import isn't set correctly, and I need to edit something else as well
Who needs help with flask
lel me but it's against the rules 😢
btw who can talk to me in private chat i need to talk about requests cause when i asked here they said it's against the rules
https://cdn.discordapp.com/attachments/291284109232308226/753703017466822686/unknown.png
csrf_token is already in the form.
the xhr is javascript ajax
for some reason its also poppin that in the cmd
I've been building a discord bot integrated with flask so some actions can be done on the web. I'm not too far in but having some issues and starting to wonder if I should be using django instead of flask.
Also when I say on the web I mean specifically in internal browser at this point. It might be cool to add it to "the web" at some point but there is no need for what I want to do with managing users and doing backups.
Depends on what the issue that youre having is if I would recommend switching @stoic prairie
I initially started Django and then quit and went to Flask, and then I realized that both are good for different things
I've been trying to use threading with flask and a lot of the errors I came up with people on stackoverflow say it is flask issue with not supporting threading
Ah, okay. I definitely dont have any input on that. Ive never tried to use threading on Flask.
Hello hello
But uh... I know that a lot of times with Discord bots in python, there are situations where you cant do things traditionally apparently, like unit tests. And I believe the way people handle that is by separating their logic from the command structure. Im not sure if that would help you here...
But maybe you could use Flask without threading, which you are using in the bot, but not in Flask? Not sure about that one. Ive never written multiprocessing code at all tbh
Could someone helpme figure out why heroku still tries to connect to elasticsearch even though I have logic that says if there is no url don't use ?
Locally, my program ignores the elasticsearch integration when I don't give a URL, but heroku keeps trying to use it
Is there like an article that gives a comprehensive view of a website
I am talking like the path from HTTP entering the system, processing it, outputting it, sending the request back etc.
Because it learning flask and trying to deploy a website but I don’t REALLY understand what is happening
can u connect flask + discordwebhook lib?
yes
dope , time to learn flask instead sleeping to school lmao
would use d.py's webhook support system https://discordpy.readthedocs.io/en/latest/api.html#webhook-support
on my github u can find what lib im using for webhooks , its much simpler for me
d.py is pretty much the only safe one other than doing it raw yourself
the others ive seen are well, spammy in places
wdym?
some of them take lists of webhooks then just flood discord with webhook posts
which will get your ip ratelimited and probably banned for a bit
its fine if youre only sending like 1 or 2
o.0 , yea i used discordWebhook or something liek that lemme check fo embed generator
but i wouldnt use those sorts of things for multiple webhooks because you'll get hit by ratelimits hard if youre not carful
Very quickly actually. I havent tried it in
and didnt have problems with it yet
Discord but other services I have seen it be a thing
I doubt you will until you send lots
Btw if you're uploading files the ratelimit is much lower than 50/s globally
cloudflare will get you before discord does when uploading files
i mean , my progam is universal , u need to give it your webhook and nobody else can use it because its stored localy and its overwrited everytime u upload new webhook link , if u want to check code its here https://github.com/micho44/EmbedGenerator
that should be fine
its not uploading webhooks anywhere other than local stored json
it just uses it to send the embed
for flask html is needed for input fields and buttons right? first time working with web dev
pretty much
honestly you could just do a form
and submit that sends a POST request with the form
would be the easiest
that doesnt tell me to much :/ like i use requests.post function? or what?
it my first time working in these regions , i only woked with local GUI apps
no i mean litterally the HTML forms system
you can also use https://flask.palletsprojects.com/en/1.1.x/patterns/wtforms/ to generate it for you
yoooooo , that forms system might actually work , but how can i get data that has been typed in?
its sent as a POST request by the html to the server
read through the link and watch a video on flask's forms system
https://www.youtube.com/watch?v=9MHYHgh4jYc - will this work? just dont want to waste time im yet on #3 tutorial and if this isnt what i should be using then i just wont watch it yet
In this flask tutorial I show you how to use the HTTP request methods Post and Get. The POST method will allow us to retrieve data from forms on our web page. In later videos we'll get into more advanced topics relating to login sessions and using POST methods to retrieve secu...
I’m supposedly supposed to make a secret key for Flask but where do I hide it, so that it does not show up in my code?
secrets.py
key = "what ever key"
main app
from secrets import key
``` ?
Say like you have other developers working on a project but you don’t want them to know what the Secret Key. they could just peek at the secrets.py folder and see what the key is
I’m supposedly supposed to make a secret key for Flask but where do I hide it, so that it does not show up in my code?
@noble star it's fine for it to be in your code
as long as your code is not public.
Oh ok
Say like you have other developers working on a project but you don’t want them to know what the Secret Key. they could just peek at the secrets.py folder and see what the key is
@noble star in this case
environment variable
or local file
that isn't, say, committed to VCS
@quick cargo i want to thank u for helping with that form suggestion , it works as i wanted! 😄
Np 👍
I tried adding a second user to my Django app, but it won’t let me log into it. I created a new name and password, typed it in exactly, and it didn’t match
I tried adding a second user to my Django app, but it won’t let me log into it. I created a new name and password, typed it in exactly, and it didn’t match
@frozen python you didn't use.create_user
right?
you used User.objects.create or something
@vestal hound I did “create super user” but I went in and clicked on “create user” and I created one, but it didn’t let me log in.
@vestal hound my super user works fine
okay, go back
you created your user
using the admin panel GUI?
not programmatically?
@vestal hound correct. I just created it in Super User.... logged out and tried to log in as that new user.... didn’t work
@vestal hound no
So, if anyone would look at my Django project structure... https://paste.pythondiscord.com/oberolipow.rb
I'm not sure how to go about having common modules. You'll notice that Ive put utils.py and constants.py at the root, which is well outside of project and the apps within it.
I'm having trouble reaching out from one app where I need code from another. For instances, from */users back out to another app. So the way ive done it is just to throw common modules at root and use the entire project as module for importing
in ts_backend/users/views.py:
from ts_backend.users.models import User
from utils import get_context
This was working for a awhile... but I did some refactoring and some time passed...
And now when I run
$ pwd
/home/shaen/PycharmProjects/term-story-back
$ python ts_backend/manage.py runserver
Im getting error :
...
File "/home/shaen/PycharmProjects/term-story-back/ts_backend/users/urls.py", line 3, in <module>
from . import views
File "/home/shaen/PycharmProjects/term-story-back/ts_backend/users/views.py", line 3, in <module>
from ts_backend.users.models import User
ModuleNotFoundError: No module named 'ts_backend'
I just added an __init__.py that wasnt there before and it didnt help. It was working last week
https://github.com/shanerowden/term-story-back/ -- it might be easier to see the project structure like this. Bleh, im almost certain its a dumb error i will see instantly when i wake up tomorrow so ill just break
If I just enter a console and type import ts_backend it does it. But from the ./ts_backend/users/views.py or any other file at that depth, it doesnt believe that it is.
from .models import User instead of from ts_backend.users.models import User worked, but now... its utils that isnt a module.
TLDR, how do you have a common app in django for utils?
I figured it out , carry on https://stackoverflow.com/questions/3295268/where-should-utility-functions-live-in-django#3295933
@native tide i usually create a new app called utils and put things like common permissions, paginators and mixins in that app
yeah, I moved those files to very root because at the time I hadnt figured out yet why I was having trouble importing a single utils.py file from outside the apps and I was trying and failing to do relative imports.
Now I have read a lot more about different project structures and Im just trying to tweak it to be a lot better than what it is.
What i was trying to do right now is have a single apps.py file in the project rather than in the apps. But it occured to me half way through getting it there that this makes my apps not modular.
So Im setting it back 😛
it should be app.py though, which I would change if not for convetion, since it will only ever have one class.
Django
Is there anyother way to change an objects value, that uses strings as an identifier ?
Instead of object.field1 = 0 something like object['field1'] = 0 ?
Django
Is there anyother way to change an objects value, that uses strings as an identifier ?
Instead ofobject.field1 = 0something likeobject['field1'] = 0?
@onyx crane hm
why?
I mean, setattr should work
Hello everyone, is anyone an expert in flask sqlalchemy?
I have a problem in delete schemes in Association Objects
anyone know what is the use of methods of model field of django from_db_value() and to_python().
hello, so i was starting off learning flask. I created my first flask file with just a '\' directory and created a sample html file to render, but i am getting a jinja2.exceptions.TemplateNotFound error. They are both placed in the same folder and i am not very sure on how to fix it. I read something about putting it in a templates folder but couldnt quite follow. Any assistance would be greatly appreciated
sqlite3.IntegrityError: NOT NULL constraint failed: accounts_user.views
somebody help me understand what this error implies in django
okay so i got rid of my render template thingy in my python file, but im still getting the same error, which is extremely strange
considering im not even calling a HTML file anymore, its giving me a "jinja2.exceptions.TemplateNotFound: test.html" still, despite me not calling test.html
oh i think i got it
lemme just check
@mental veldt your User model has an attribute called views which is not getting any value assigned to it
nope i did not lmao
@mental veldt your
Usermodel has an attribute calledviewswhich is not getting any value assigned to it
@versed python I was trying to create a custom user with AbstractUser. Could this be because i havent added any views yet?? do I need to add views before making migrations??
@versed python oh sorry I get it. I was thinking about the views module, forgot I have a views field in my models. lol
alright i finally figured it out, like a tool i had another flask app running simultaneously
@mental veldt not really this is not a models problem
yeah you got it
@versed python oh sorry I get it. I was thinking about the views module, forgot I have a views field in my models. lol
@mental veldt
@versed python Yeah thanks
you're welcome
@versed python How are you so good with Django?? Its like you know everything
anyone know what is the use of methods of model field of django
from_db_value() and to_python().
@stable kite
You can use them to convert values.
From DB to python object : from_db_value() and to_python() will be from user input value to python object, this method is also called in the clean() method used to validate forms.
You can find more info in Django doc :
from_db_value() : https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.Field.from_db_value
to_python() : https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.Field.to_python
Converting values to Python objects : https://docs.djangoproject.com/en/3.1/howto/custom-model-fields/#converting-values-to-python-objects
Form and field validation : https://docs.djangoproject.com/en/3.1/ref/forms/validation/
i spent a lot of time wracking my brain over it, and have encountered most of the problems that get asked here myself. back then i wasn't on Discord so I had to do hours of research before I found out a solution, so maybe that's the reason?
thanks for the compliment though @mental veldt
@versed python you are welcome. I always find solutions for django problems on discord thanks to people like you
the pleasure is all mine :D
@native tide whats wrong with your models?
@versed python Which one would you recommend using when creating a custom user?? Either AbstractUser or AbstractBaseUser? I have read articles that warn a lot against the use of AbstractBaseUser
I usually use AbstractUser, AbstractBaseUser is only really for a super high level of control and customization, from what i understand. Ive never actually needed to use AbstractBaseUser though
they're right, this is what I do too
@acoustic oyster @versed python I was trying AbstractBase user and I have found myself in a big mess.
maybe I should take that route
as @acoustic oyster said, you should only go with AbstractBaseUser when you know what you are doing
AbstractUser is more than enough for most projects
Haha, I did the same. You could maybe inherit from abstract user? Lol.
I ended up hard coding a lot of things that I needed because we accidentally used baseuser
I also have this project where I want to have like a number of views counter which increments everytime someone views a profile. what would be the best approach?
implement this on the view level maybe? are you using rest_framework?
@native tide am using rest_framewor
I added a views field on the models as an IntergerField then i was thinking I would have a function in the views module. but what I want is to detect that someone has actually viewed the profile.... I have no idea how to do that
can you send the view logic itself.? if you use class based views, maybe you can override the get method and increment the view attribute? @mental veldt
I dont have the logic. I deleted what I was trying. but I think it had
def views_counter(self, request):
views = 0
if (someone visits the profile):
views =+1
retrun views
nope, use rest_framework.views.RetrieveUpdateView for this and override the get method. Your code will be much smaller this way.
RetrieveUpdateView works for both get and put methods right?
yeah and also PATCH i think
Isnt PATCH the same as PUT?
Isnt PATCH the same as PUT?
@mental veldt PUT is for full updates
PATCH is for partial updates
basically.
@umbral echo thanks
What is the de facto standard for RESTful Flask?
In case I decide to apply for a job that uses that instead of Django and ariadne like I would prefer
Flask-RESTful any good?
PATCH is for partial updates
@vestal hound ok
Hey Guys
I currently using Django with the Rest-Framework + Django Filter. Im happy so far but i ran into a problem:
How can i filter my model with an "or" condition instead of "and"?
Exp:
url.com?param1=abc¶m2=bca
in the current situation i only get the results back when both conditions are true
but i want an "or" condition. So if any of the fields match -> return
@broken briar use a Q object: https://docs.djangoproject.com/en/3.1/topics/db/queries/#complex-lookups-with-q-objects
I know about the Q Object, but can i somehow get this into this structure i currently have
class myFilter(FilerSet):
field1 = filters.Filter(field_name='field1, lookup_expr='icontains)
field2 = filters.Filter(field_name='field2, lookup_expr='icontains)
class Meta:
model = myModel
fields = ['field1', 'field2']
class Viewset(Modelviewset):
queryset = myModel.objects.all()
serializer_class = ...
filter_backends(django_filters.rest_framework.DjangoFilterBackend)
filterset_class = myFilter
``` @lethal orbit
If you have time to look at my Django models, they're pretty simple. I keep getting django.db.utils.ProgrammingError: relation "users_playeraccount" does not exist.
I've reset the db, dropped the tables and the entire database multiple times, created it again, so i think it has to do with that models file unless Im failing to remove everything I need to remove to start over in postgres.
Originally this problem was a "are you sure you want to change this name" and then fails. Now its just that error.
https://github.com/shanerowden/term-story-back/blob/master/project/apps/users/models.py
When I put those routes this way, it work
but if i do this, it doesn't
and gives me this error
any idea why?
oh nevermind, just tried this and it worked:
path('<int:pk>/', views.driver_details_view, name='driver_details'),
if the routes are all the same, the pattern matching ones should go last
can someone help me to build a website?
@deep owl no one is gonna do that. we help when you get an error
that's just too broad a help to ask
i have no idea thats why im asking
In this Python Django Tutorial, we will be learning how to get started using the Django framework. We will install the necessary packages and get a basic app...
i want to build a site
here's an excellent series
actually you have to choose between flask and Django
what's good for a beginner?
there are a few other frameworks but idk about them
Flask is generally easier, but I personally started with django and find it easy enough
you should look up a guide on internet about flask vs django and then choose one @deep owl
yeah
get started with it. you'll probably understand absolutely nothing the first time you watch the series
don't worry you'll start getting it soon
just make sure you follow along
okay thank you, can i add you on discord?
yeah sure
okay
Sep 11 13:39:19 gamestars apachectl[45630]: AH00526: Syntax error on line 49 of /etc/apache2/sites-enabled/gamestars.conf: Sep 11 13:39:19 gamestars apachectl[45630]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration Sep 11 13:39:19 gamestars apachectl[45611]: Action 'start' failed.
Following a tutorial where I was told to download libapache2-mod-wsgi-py3 but then I get the above error ^
From what I've found on stackoverflow I need to install libapache2-mod-wsgi instead but this says it'll uninstall libapache2-mod-wsgi-py3
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/board/{%25url 'home' %25
Using the URLconf defined in post.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
about/
board/int:boerd_id [name='board_topic']
The current path, board/{%url 'home' %, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to Fal why this??????????
@mystic wyvern you need to go to http://127.0.0.1:8000/board/12/ or some other integer like that
guys should I handle notifications in the frontend in the backend or frontend?
meaning do I create the notification data in the frontend and thyen send it to the backend to save in a model, or create the notification in the backend and send it to the frontend?
What is the notification for?
for example "your Post was created and published successfully" @lethal orbit
ideally I should do the logic handling in the backend right
Depends...
If you are pushing from the client to the server, you can save it in indexeddb as pending....
whats indexddb? I am using Vuejs
Then send the request to the back-end. When the promise resolves, you sent a client-side notification.
https://github.com/Maronato/vue-toastification I will probably be using this to display notifications
Indexeddb is optional.
Can implement a Q Object into this code?
class myFilter(FilerSet):
field1 = filters.Filter(field_name='field1, lookup_expr='icontains)
field2 = filters.Filter(field_name='field2, lookup_expr='icontains)
class Meta:
model = myModel
fields = ['field1', 'field2']
class Viewset(Modelviewset):
queryset = myModel.objects.all()
serializer_class = ...
filter_backends(django_filters.rest_framework.DjangoFilterBackend)
filterset_class = myFilter
Then send the request to the back-end. When the promise resolves, you sent a client-side notification.
@lethal orbit yeah this is what I was thinking too
What modern sites do...
They store data in indexeddb (which is just a client side DB). If it fails, you give the user an option to retry.
is it some kind of localStorage?
But yeah, if you send requests from the client to server, don't store notifications on the back-end. Send the request in a promise, and when it succeeds, then() notify the user on the client.
Yes and no. A more proper DB.
You could use LocalStorage too (or not store it at all).
But yeah, if you send requests from the client to server, don't store notifications on the back-end. Send the request in a promise, and when it succeeds,
then()notify the user on the client.
@lethal orbit but what if I have aNotificationmodel for storing them? I actually want to store them
You really only need to store notification on the server for server events...
User A pushes a message to User B on the back-end... the server notifies User B that they have a new message
For upload succeeded, I wouldn't bother, tbh
so you are saying I shouldn't store "Your post was saved and published successfully" in my django backend database?
@lethal orbit
Well then should I delete the Notification model altogether?
If it's just for client events, I would say probably, yeah :p
so what would you use a Notification model for then?
As I said, if the server sends notifications from another source, it makes sense to have one.
"A new movie you might like has been added"
User foo sent you a $5 virtual gift.
Those require some action from the server.
User sending stuff to the server is a client-server interaction, not server-client.
alright, so from what I see, I should probably keep the model but not use it for useless stuff like 'Your post was saved and published successfully'
and just display it on the client side and not bother sending it to the backend right?
Yup
If you don't have server events to notify the user about, you can delete the model. No need to delete it now, though. Take some time and see whether there is a use case for it.
yeah as of now I will keep it as it is. Thanks @lethal orbit you helped a lot
Can i use asyncio in a flask app to wait for a db query? or that's not a case?
assuming the folder structure is fine and the app is in installed apps, there is a {% load static %} tag you have to add in the template for it to successfully work
It's not giving me any error, I'm doing <script src="{% static 'home\home.js' %}"></script>
And this is the JS ```// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the navbar
var navbar = document.getElementById("navbar");
// Get the offset position of the navbar
var sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}```
gotcha. if its not loading then someone else will have to help, I'm still pretty new with js myself. sry I can't help
the fact it loaded though indicates everything w/ django is fine
It's not giving me any error, I'm doing
<script src="{% static 'home\home.js' %}"></script>
@twilit dagger why are you using a\?
This might not be the problem, but they should always be forward slashes (/)...
@lethal orbit Sorry that was a mistake, I was also doing {% static 'home\main.css' %} like that
Been using django for 3 and a half years now and had the joy of a brand new error today. Django/postgres complain about too many connections to DB.
hi guys is this chat an okay place to ask a question about selenium?
im trying to help a friend of mine with an issue
hes trying to make a bot that gives kudos in strava
the button hes trying to target is
<button class="btn btn-icon btn-icon-only btn-kudo btn-xs js-add-kudo" data-entry="["Activity",4038233087]" str-on="click" str-trackable-id="ChYIBTISCP+XyoUPGAIoATBdOABAAEgBEgQKAggD" str-type="kudos" title="Give Kudos">
<span class="app-icon icon-dark icon-kudo icon-sm">
kudos
</span>
</button>
initially he had a line that looked like
buttons = driver.find_elements(By.XPATH,"""//button[@title="Give Kudos" and starts-with(@data-entry,'["Activity')]""")
ive changed that to
buttons = driver.find_element_by_xpath("//button[@title='Give Kudos']")
however it still doesnt seem to target it properly
its my first time looking at selenium as im usally a powershell groovy developer
Exception has occurred: NoSuchElementException
Message: Unable to locate element: //button[@title='Give Kudos']
File "C:\Users\bendo\Desktop\strava_palaver.py", line 33, in <module>
buttons = driver.find_element_by_xpath("//button[@title='Give Kudos']")
hmm is it full inspect element > copy xpath pasted?
ahh when I inspect the element and copy the xpath its
/html/body/div[3]/div/div[2]/div[2]/div[1]/div[2]/div[3]/ul/li[1]/div[4]/div/div[2]/button[1]
I assume thats wrong as it doesnt look right to me
buttons = driver.find_element_by_xpath("/html/body/div[3]/div/div[2]/div[2]/div[1]/div[2]/div[3]/ul/li[1]/div[4]/div/div[2]/button[1]")
try that
I get Unable to locate element: /html/body/div[3]/div/div[2]/div[2]/div[1]/div[2]/div[3]/ul/li[1]/div[4]/div/div[2]/button[1]
on the website (strave) there is multiple kudos buttons that he was trying to loop through and hit
https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web Is this a good place to start learning about web development?
if it's from Mozilla it's bound to be good @thorny badge
Guess ill follow through then, thanks :))
thanks for your help @errant spear though i am not getting an internal server error
You are not getting an internal server error?
I am now*
Ok can you give me some more information on the error
What is the exact error you are getting? What are you trying to do when you get this error? What do you expect to happen instead?
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.```
so basically i have 1 script that makes a request for a stiemap in xml format, it then parses that xml into a dictionary of urls that have been updated in the last 3 days
it then stores that dicitonary into a variable
which i am then importing into my flask routes
Ok so it seems like there is some sort of error in the code that is displaying this page
well
the error i posted is the message output I got when visiting the flask route
i am wondering if the dictionary variable actually contains a dictionary
So when you run a flask app in the command line you have to run the app.py file
Are you familiar with that?
yes
you know what though
my parse script
has a if __name__ == "__main__": main()
and so does my run.py
ok well whichever one you are running in the command line where it is being run there should be more information on the error and why the page isnt displaying
one second
Ok cool
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Knowledge Articles</title>
</head>
<body>
{% extends "staff_parent_template.xhtml" %}
{% block content %}
<h1> Welcome to the Knowledge Articles page </h1>
<p> these are the new articles for today </p>
<h3>DICTIONARY: {{ dict_to_be_passed }} </h3>
<h3>DICTIONARY FIELD: {{ dict_to_be_passed['field_name'] }}</h3>
{% endblock %}
</body>
</html>```