#web-development

2 messages · Page 108 of 1

stable kite
#

@winter spindle here is the link for django's tutorial

winter spindle
#

oh okay thanks i will check tht out

tribal lichen
#

Hello guys....I just came across Python Tutor. It is awesome and i visualized my linked list code on it. I want to make my own Linked list visualizer wherein i can visualize the operations on Linked list like insertion at head, tail and deletion at head, tail etc. I am good in C++ and know basics of python

prime nest
#

is there a channel for game makers?

tribal lichen
#

Do you want to make a blackjack game??

prime nest
#

no?

winter spindle
#

hey should we make a new virtual env for each django project ?

devout coral
#

I would suggest a new venv for every new project

stable kite
#

hey should we make a new virtual env for each django project ?
@winter spindle yes

winter spindle
#

ohh okay

#

@devout coral @stable kite so you guys use anaconda ?

devout coral
#

I do not, why?

winter spindle
#

like i create a venv using anaconda

#

so like the other tutorials which i see they get a venv file in the folder structure

#

but like i dont get any such file

stable kite
#

no

winter spindle
#

wht no ?

#

@stable kite

stable kite
#

@winter spindle so you guys use anaconda ?

winter spindle
#

yea yeah

#

i use anaconda

young oyster
#

hi there, I want to use postgres ArrayField with django, but idk how to get rid of the warning 003 (arrayfield default should be a callable)
I tried this:

communications = ArrayField(models.CharField(max_length=200), default=get_default_email())
...
def get_default_email():
    return 'Noticias, Promociones, Pagos, Compras'.split(', ')
``` But no luck... docs say: `If you give the field a default, ensure it’s a callable such as list (for an empty default) or a callable that returns a list (such as a function). Incorrectly using default=[] creates a mutable default that is shared between all instances of ArrayField.`

Can anoyone give me an idea of this?

static harbor
#

how to have foreign key of same model for example this

class Role(models.Model):
    roleName=models.CharField(max_length=50)
    description=models.CharField(max_length=100)
    roleReportsTo=models.ForeignKey(Role,null=True) 
#

roleReportsTo=models.ForeignKey('self',null=True)

#

I think this can work

native tide
#

why do you need a foreign key of the same table?

nova nacelle
#

@static harbor Just make another model called reportrole, where some "X" is foreign key to the role table/model.

static harbor
#

@native tide
in this example
manager can be report to ceo
so table would look like
1 ceo ceo_desc null
2 manager manager_desc 1

so this way manger is reporting to ceo

native tide
#

Ok... I guess

steel tiger
#

Anyone know how to manage docker-swarm from github actions? Would like to integrate a cool "master push -> autodeploy"

warm igloo
steel tiger
#

Only 15 stars

#

Doesn't seem to be any tutorials and i'd rather do something more tried and tested sort of thing

warm igloo
#

Cause swarm is on its last legs before death? 🙂

steel tiger
#

It is?

warm igloo
#

GitHub Actions is so new I'm not sure how much tried and tested things you'll find.

#

Eh, people say Swarm is on its way out. k8s or bust basically. But a lot of things pointing to Swarm not going to grow or get much development attention. But that could just be k8s fanboys and/or swarm detractors. Use what works well for you, but you'll definitely find less swarm stuff out there than k8s for instance.

steel tiger
#

Not using k8s because its overkill and cba learning the whole thing for a small cms

warm igloo
#

yeah I agree that k8s is often overkill

#

people try to use it even for the smallest of things which is silly

steel tiger
#

Swarm seems like the obvious small app with a couple containers sort of thing

warm igloo
#

yeah, then again, you can go pretty far for small projects with just compose

steel tiger
#

What's the difference between global and default for containers?

#

I see I can assign nginx as global but no idea what that means in compose

#

For nginx, should I have 1 per container?

warm igloo
#

nah, for instance, I have a single nginx container that is the switchboard operator more or less .. so I can map virtual domains and such and it handles it all. Including SSL (so my nginx has SSL and I have a wildcard cert and then I don't have to configure SSL per container)

#

Look up jwilder/nginx-proxy .. it made doing some cool things on a single vm with docker pretty damn easy

#

I tweaked his a bit, let me see if I have it public

steel tiger
#

Ah i've already got an nginx proxy made

#
upstream api_server {
  server api:5000;
}

server {

  listen 80;
  server_name localhost;

  location / {
    proxy_pass http://api_server;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
  }

}
#

Just passed that into the default image with a modded nginx.conf with typical defaults/security settings

warm igloo
#

Thor was my experiment box to try this all on. To be replicated to Odin as a "production" environment. Of course my POC turned into the prod box suddenly lol.

steel tiger
#

Ah yeah

#

How would I attach load balancing and such to this or would I just publically expose these nginx servers

#

And just do a ton of cloudflare dns to align a decent hostname onto it

whole jungle
#

you would add more servers to the upstream to load balance.

trim star
#

I have a django question: where is the processing code typically defined for the url end? For example example.com/notifictions
Where would the code be to process data sent to the notifications endpoint?

wise lagoon
#

hello um why is this a syntaxerror in jinja2?

{% title = "{% block title %}{% endblock %}" %}
{% if title != "" %}
    <title>{{ title }} - GummyFN</title>
{% else %}
    <title>GummyFN</title>
{% endif %}```
and how would i do this?
wise lagoon
#

bruh why this chat so inactive

young mesa
#

#bot-commands

cerulean forge
#

how to make mobile app w/ python me lazy

toxic flame
native tide
#

@cerulean forge well the backend/API at least can be done with django no problem

#

on my current project, I'm making a reactjs single page app using axios for the API calls, and using django/djangorestframework as the backend. they pair just fine once you understand the moving parts

cerulean forge
#

@native tide sure.

native tide
#

lol, alright then

#

Hi

bronze blaze
#

good afternoon, may I ask something here?

somber aurora
#

Sure

native tide
#

Hi, maybe it is some kind of offtop, but what js framework can I use to program my website as discord bot's settings page?

#

Or how is it working?

#

Maybe I should make something like api support

native tide
#

@wise lagoon blocks aren't right

#

@cerulean forge what??

#

@native tide good luck on the react bro, I'm using it too + axios but I'm trying to make an MPA with it 😄

wise lagoon
#

@wise lagoon blocks aren't right
@native tide ? how would i do this then?

native tide
#

Firstly, I don't think this is correct:
{% title = "{% block title %}{% endblock %}" %}

wise lagoon
#

yea ik that is my error

#

how would i do it?

native tide
#

{% block title %}{% endblock %} will insert the content between the blocks into a template (which also has the same blocks)

#
{% block content %}
    <title>{{ title }} - GummyFN</title>
{% endblock %}
#

So why can't you just do this, and pass title from your function?

wise lagoon
#

i forget most times and its a pain in the but too look through my 200 or so line file

#

so thats why i wanna do it like that

native tide
#

I don't understand what you're trying to say

wise lagoon
#

i just wanna do this:
index.html

{% extends "base.html" %}
{% block title %}Home{% endblock %}```
base.html
```jinja
<!DOCTYPE html>
<html>
    <head>
        {% title = "{% block title %}{% endblock %}" %} <!-- error here -->
        {% if title != "" %}
            <title>{{ title }} - GummyFN</title>
        {% else %}
            <title>GummyFN</title>
        {% endif %}
    </head>
    <body>
        <h1>test</h1>
    </body>
</html>
native tide
#

Yea, and I gave you the solution to that

wise lagoon
#
{% block content %}
    <title>{{ title }} - GummyFN</title>
{% endblock %}

yea but thats not really what i want

native tide
#

So, what do you want.

{% block title %}
  {% if title !="" %}
    <title>{{ title }} - GummyFN</title>
  {% else %}
    ...
  {% endif %}
{% endblock %}
wise lagoon
#

i want title to be a block that i can set when i am extending the base.html file and i want that block to be set as a variable (as a string) so i can check if its empty and if it is empty put just GummyFN as the title else if it isnt put {{ title }} - GummyFN as the title

#

understand me now?

native tide
#

Yep... and there's your solution

wise lagoon
#

wait does title become a variable when u set it as a block?

native tide
#

no. that's just a name

#

@wise lagoon try the code above

#

Read through the docs that would be your best bet

wise lagoon
#

wait is it even possible to set a variable in a with statement to the value of a block?

native tide
#

can you elaborate

wise lagoon
#

i mean can i set something that i input through a block to a variable?

native tide
#

@wise lagoon what do you mean by "input through a block"?

#

You pass a variable from your function to your block

#

not vice versa

wise lagoon
#

thats not i mean

#

i mean i want to set a block in my base.html file and get the value of that block in a variable

polar trellis
#

I don't think you understand how Jinja templating works

native tide
#

Yea

#

You pass a variable from your function to your block
@native tide @wise lagoon

#

A block doesn't have a "value"

#

A block renders content in your template

#

Information is passed from your function -> block

wise lagoon
#

what do you mean by "my function"

native tide
#

The function which handles the rendering of that page

polar trellis
#

what are you using flask or django

native tide
#

looks like flask

wise lagoon
#

jinja

#

just jinja ingeneral

native tide
#

so... you're using flask?

wise lagoon
#

umm not really

#

im using flask rn as a tester but im going to convert the page into sanic because i need to do some async stuff in it

native tide
#

ok. you could've said yes at the start

#

In Flask you'll write a function which renders that page @wise lagoon and then from that function you can pass in a title

polar trellis
#

read this part hopefully you will understand better

wise lagoon
#

yes ik thats how i previously did it

native tide
#

So what's the issue here

wise lagoon
#

aaand were back at the start

native tide
#

I've answered your question

wise lagoon
#

not really

native tide
#

Then elaborate

wise lagoon
#

can i just explain my question first?

native tide
#

That's what I'm asking

#

🤦

wise lagoon
#

i wont go in depth on what im tryna do

#

ok so im extending base.html which has a title block

#

from my index.html file i want to set that block to be for example Home Page

#

on the base.html file i want to capture that block and in a with statement set a variable to what the block is which rn should be Home Page

#

and when i have that variable i want to see if its blank

#

if it is then i want to set Title as the title of the page

#

if it isnt i want to set {{ title }} - Title as the title of the page ({{ title }} is gonna be for example Home Page)

native tide
#

So how does this not fit your criteria?

{% block title %}
  {% if title !="" %}
    <title>{{ title }} - GummyFN</title>
  {% else %}
    ...
  {% endif %}
{% endblock %}```
wise lagoon
#

lemme test it

polar trellis
#

it doesn't i think what he is trying to do is probably not possible

wise lagoon
#

why?

polar trellis
#

or you could but bot like this

native tide
#

Bruh I gave you that like 20 mins ago and you didn't test it

polar trellis
#

how you want to solve it now

#

for your index.html you probably need something like this:```
{% extends "base.html" %}
{% set title = "string" %}

wise lagoon
#

wait theres a set keyword

native tide
#

@wise lagoon you can do the same thing from your function

#

You pass a title to the template

wise lagoon
#

i dont want to do it from my function tho

native tide
#

Then how you gonna do it then 😂

wise lagoon
#

thats the entire point of this question

#

lmao

native tide
#

@wise lagoon How will the template know if the title is empty or not?

#

You have to pass a title to the template

polar trellis
#

otherwise you will have to use a workaround and use javascript

native tide
#

All this could've been avoided if you a) read the docs b) watched a tutorial

polar trellis
#

if you want to do it by passing in a html string like your doing now you probably will need javascript to grab the value and update the title

wise lagoon
#

for your index.html you probably need something like this:```
{% extends "base.html" %}
{% set title = "string" %}

@polar trellis that kinda worked

prisma jackal
#

What form.cleaned_data.get() is doing in django

native tide
#

@prisma jackal the docs explain that

prisma jackal
#

I can't understand it that's why I ask here.

#

@native tide

native tide
#

when you submit a form, the information will be in a dictionary in the format {field: value}. The fields are the fields of your form, e.g. username or password and they are matched to what the user inputted.

e.g.

{"username": "foo",
"password": "bar"}

This dictionary is form.cleaned_data in django. Then with any dict you can .get() to get the value from a key.

So for our example is we do form.cleaned_data.get("username") we get "foo". Understood? @prisma jackal

prisma jackal
#

Yes! thank you

native tide
#

np 🙂

normal kite
#

I have a website with 2 pages, I need it to link to my home page when i click the home button, but the url for my hope page is blank like its just [sitename].github.io, it has no ending. How do I refer to it? I tried doing index.html but it takes me to [sitename].github.io/index.html.

#

nvm got it

native tide
#

@native tide yeah js/react is a completely different animal compared to python, but the backend part of it at least is very simple thanks to django and a few other libraries. happy halloween!

#

totally agree. you too my man 🙂

void cosmos
#

Hey I have some simple programs, scrabble word finder and hangman that I want to make a gui of and put on my django site I made. Problem is I'm unsure on where at all to start on this.

empty aurora
#

I'm writing an API with flask, what would the proper HTTP code be for
"We found the object you requested, but it doesn't contain the data you requested"

#

like for the sake of example, say you have a database of users and each user contains the name of the users cat

#

and you request api/users/id123/cat

#

but the user doesnt have a cat

#

404 doesnt really make sense because does that mean user id123 wasnt found or their cat wasnt found?

devout coral
#

@void cosmos So you have your Django project made and the games and want to combine them? Or you have the games and want to make then available on the web with Django?

void cosmos
#

@devout coral Yea I have the games and project ready. Although i don't actually have a gui for the games its just text based atm which would probably be better to start off with

devout coral
#

Ok, good thing you don’t have the GUI lol. You’ll need to recreate it with JS anyways.

void cosmos
#

I thought i might

#

that's why i was asking 🙂

devout coral
#

You have the Django site all set up and ready to go? All you need to do is implement the games?

void cosmos
#

yea i've made a basic blog

#

some templates etc

devout coral
#

Well, this wouldn’t be a blog lol

void cosmos
#

I know

#

I'm just practicing

devout coral
#

I am guessing you will just start fresh then ?

void cosmos
#

I can change the blog to a portfolio or anything pretty easy its only bare basics

#

just been messing around

devout coral
#

So are you wanting to serve to the user everything with JS then do all the logic in python?

void cosmos
#

I don't even mind if its something basic like they fill out a form and then through the form it does my python code then gives them the answer

#

I just have literally no idea where to start on something like this

#

Scrabble word finder just needs the input

devout coral
#

Ok, well I’d suggest you probably start with the hangman as it will be easier IMHO.

void cosmos
#

you reckon? scrabble word is just literally input 1 rack

#

and it gives you all the possible words

#

thought that'd be easier

devout coral
#

Well the reason I say hangman is you can display the little image, and the amount of blank lines for the word and phrase. Then all you need to do is display an alphabet where the user can click a letter. On letter select it does a post with Ajax to a view and returns the result.

#

Once you get the response you can update everything with JQuery.

#

Orrrrr you simply do everything with JS. Logic and all.

void cosmos
#

Yikes

#

I'd need to learn js to do that

#

lol

devout coral
#

Yeah, you will need to know it no matter what lol

void cosmos
#

Yea still trying to learn python really

devout coral
#

You will probably want it to render everything

#

Oh...

void cosmos
#

so trying to not make that mistake of jumping to many different things

devout coral
#

Ok

#

Why not just make the games using py game first?

#

Then later move into the web aspect of it

void cosmos
#

I actually started looking at pygame after i commented

#

Figured I got basics of django down so can always come back to it

#

and actually start doing a blog/journal now

devout coral
#

Yeah, running py game on the web while doable is not recommended so you would want to re create the games with js. At least the GUI.

void cosmos
#

I just thought it'd be fairly simple to implement a text based game on to django

devout coral
#

Honestly if you are still learning python I would say finish these two games with full guis. Then maybe try making them multiplayer

#

Well text based sure. You would still need a little JS (not hard honestly) for the updating of values and stuff. Unless you want refreshes after every move.

void cosmos
#

Yea that's why i wanted to try scrabble one first. It's pretty simple text based one atm

devout coral
#

Well, if you don’t mind the refreshes then you can handle everything like a regular Django form.

void cosmos
#

That's what i was thinking of trying now. I was going to do this the most simplest way possible then build on it

#

I figured it'd have to refresh without some js

devout coral
#

I mean honestly the Js isn’t too bad.

#

But you are still grasping Python so it’s a good plan.

#

Start small then build on it

#

Good Luck, and feel free to send a message if you need help while implementing.

void cosmos
#

the second answer from kossta seems to be something i could use

devout coral
#

Yes, it’s like a regular Django form submission right(

void cosmos
#

yea that's what i was thinking of using as the input

devout coral
#

Yeah, that would work.

void cosmos
#

alright I'll give it a crack thanks for the advice

devout coral
#

Alright, cheers!

chilly falcon
#

hello

#

anyone to talk?

sudden lynx
#

hey, what is the best way to start learning django, currently im low on budget, so purchasing multiple books is not an option, also django docs seem quite hard

stable kite
#

@sudden lynx follow the official django tutorial

sudden lynx
#

i tried, but feels too hard for newbie in webdev

brisk wadi
#

I just want to know, what is the difference between app routes, and just htmls in folders, aka both uses the /
No app route: localhost/login/index.html
@app.route('/login'): localhost/login
I really don't find what can I use it for

stable kite
#

@brisk wadi routes are like proxies for your html

brisk wadi
#

I still don't get it

#

Why should I use routes

#

and not just folders

stable kite
#

because you can name your routes anything

brisk wadi
#

Yeah but like, I will tell you my scenario, I have a static project (aka only HTML CSS JS), with around 60000 files, when I app routed an html, it kept failing to navigate to the folder of css through localhost

#

What can I do in this case?

#

I can't just routes 2400 folders

stable kite
#

routes are only for view &not for all files

brisk wadi
#

So? What can I do for my files?

stable kite
#

are you using some framework?

brisk wadi
#

Flask

stable kite
#

I don't have much idea about flask because I use django

brisk wadi
#

I used to use django

#

But for my project

#

Django is so advanced for it

stable kite
#

but i think you can store all your files in a single directory

#

then tell flask to look for it

#

whenever you need specific files

brisk wadi
#

the css files are around 500 files, and many of the htmls had already been meta tagged to get to that specific folders

snow dragon
#

💯 if you have 2400 folders, just put them all in a single top-level directory. Although you shouldn't actually use Flask to serve those static files.

tall plaza
#

hi, I am trying to serialize the same model by using two different classes. in which one class serialized all field of models and other only 2 or 3 field of same model
but its not happening
anyone have any idea
why i am creating two serializer classes well one for admin user and other for normal user.
where admin can see all serialized field of model

brisk wadi
#

💯 if you have 2400 folders, just put them all in a single top-level directory. Although you shouldn't actually use Flask to serve those static files.
As I said, changing the actual directory of them, will ruin many of the htmls

stable kite
#

hi, I am trying to serialize the same model by using two different classes. in which one class serialized all field of models and other only 2 or 3 filed of same model
but its not happening
anyone have any idea
why i am creating two serializer classes well one for admin user and other for normal user.
where admin can see all serialized field of model
@tall plaza what framework do you use?

tall plaza
#

django

stable kite
#

for serailzers?

snow dragon
#

@brisk wadi Not sure I follow. How does moving a file "ruin" HTML? hard coded paths?

brisk wadi
#

Unfortunately yes

#

Hardcoded

tall plaza
#

for serailzers?
@stable kite wait

snow dragon
#

Are they not relative paths?

#

@brisk wadi Grab a help channel, may be easier

tall plaza
#
    

    class Meta:

        model = same
        fields = '__all__'
class OnlySameSerializer(serializers.ModelSerializer):

    
    

    class Meta:

        model = same
        fields = ['name',  'descriptions']```
brisk wadi
#

I doubt anyone will help there tho, but I'll try

snow dragon
#

I'll help there. Will just be easier since others are using this channel also.

stable kite
#

@tall plaza are you using django rest framework?

tall plaza
#

yeah

#

yeah drf

stable kite
#

ok

#

where are using this serialzers in your views?

tall plaza
stable kite
#

show your views?

tall plaza
#

i mean i am just creaitng api

#

with no front end

stable kite
#

can you post your views so i can see it.

#

because that were your serialzers works

tall plaza
#
    queryset = Same.objects.all()
    
    serializer_class = SameSerializer
   
   

class OnlyViewset(viewsets.ModelViewSet):

    queryset = same.objects.all()
 
    
    serializer_class = OnlySameSerializer```
stable kite
#

ok thants fine

#

have you added it in your urls?

tall plaza
#

i am getting output of only of OnlyViewset

#

yes

#
router.register('OnlySame/', views.OnlySameViewset),```
stable kite
#

are you getting any error?

tall plaza
#

no

#

both url producing same output

stable kite
#
router.register('OnlySame/', views.OnlySameViewset),```

@tall plaza your views name is wrong here

tall plaza
#

if i dont use OnlySame url then it works fine

stable kite
#

it should be views.OnlyViewset

tall plaza
#

yeah it is

#

still not resolved

stable kite
#

but code you posted had wrong view

tall plaza
#

no i have correct

stable kite
#

can you share your models?

tall plaza
#

    name = models.CharField(max_length=200)

    descriptions = models.CharField(max_length=300, null=True, blank=True)
    profit = models.FloatField(default = 0)
stable kite
#

and what about dishes model?

#

because thats what you have used in view

tall plaza
#

no its ```same```` model

stable kite
#

wdym by same model?

#

ok you just edited you views code that you posted

tall plaza
#

yeah

#

look what i want to do here admin can see all fields of this model but normal user can only see 2 fields that is name and descriptions

#

but both url gives output same

#

output is name, descriptions

#

you got my problem ?

#

lets say if i dont use router.register('OnlySame/', views.OnlySameViewset), then i get all field of model

#
router.register('OnlySame/', views.OnlySameViewset)``` but when i use both url then ```router.register('Same', views.SameViewset)``` gives   same output as ```router.register('OnlySame/', views.OnlySameViewset)``` output
#

any idea?

#

    name = models.CharField(max_length=200)

    descriptions = models.CharField(max_length=300, null=True, blank=True)
    profit = models.FloatField(default = 0)``` here is class it has 3 fields. so what i want to do here that admin should see the all 3 fields here and normal useronly should see name, descriptions field.
#

this is what i want to do here

faint umbra
#

Hi i have been trying to find a way to avoid typing python -3 manage.py [arg] everytime.. Is there any way to just type django [arg] or dj [arg]? I checked the custom alias docs for powershell but i didnt understand its usage with arguments.. I am on windows 10

#

solved ty

stone wren
#

can we write cli commands with typer (tiangolo) in FastAPI?

#

I actually did but when I do python main.py mycommand it does not output

#

there is even some delay

void cosmos
#

if i have a textfile saved in an app in django how can I loop through it in anohter part of that app?

#

or just even access the textfile

long forge
#

Having some problems with the django tutorial for windows

#

Once I have py manage.py shell open, I am trying to confirm that the Question.objects.all() query works

#

But it just spits out a huge stack trace error that I can't really decypher

stable kite
#

Having some problems with the django tutorial for windows
@long forge can you post your error

long forge
#

sure 1 sec

#

what the fuck it works now u_u

#

alright well that's frustrating but I'll take it

#

ok nevermind now I have a new error

#

Question.objects.get(pub_date__year=current_year) is input

#

see also:

long forge
#

yeah i cant show the django admin :(

#

Oh my god you're kidding me

tall plaza
#

@stable kite

#

any idea

stable kite
#

ok nevermind now I have a new error
@long forge this error is because of your timezone settings

long forge
#

Yeah I found it in the end

#

it was my timezone being wrong as you said

stable kite
#

have you created was_publishes_recently()

long forge
#

nah that's meant to be inbuilt

stable kite
#

no its not by default

#

check the tutorial

long forge
#

I do note its referred to as a custom method though, so maybe it's just an artefact of an older version of the tutorial

#

wait nevermind

#

I found the bit you're talking about

#

I'm talking out of my ass

#

confused as to why the page search didn't pick it up tho

#

welp thank u for that

stable kite
#

here it is mentioned

#

the definition of the methods

long forge
#

yah I think I just have brainrot

#

ty for that, I think I get what's going on now

stable kite
young oyster
#

guys, where can I find a good guide of security measures for end users and how to implement it? For example, I'm thinking about MFA, security questions, and maybe something else but idk what, I need ideas haha

stable kite
#

guys, where can I find a good guide of security measures for end users and how to implement it? For example, I'm thinking about MFA, security questions, and maybe something else but idk what, I need ideas haha
@young oyster can you elaborate your questions?

native tide
#

@long forge Also, if you haven't already, run python manage.py makemigrations and then python manage.py migrate to update any changes to your models when you make them

static harbor
#

so I am makin an example app and have

class Employee(models.Model):
    empName = models.CharField(max_length=50)

class Role(models.Model):
    roleName=models.CharField(max_length=50)   roleReportsTo=models.ForeignKey('self',null=True,on_delete=models.SET_NULL) 

class EmployeeRoleMap(models.Model):
    empId=models.ForeignKey(Employee,on_delete=models.CASCADE)
    roleId=models.ForeignKey(Role,on_delete=models.CASCADE)
    startDate = models.DateField()
    endDate = models.DateField(null=True, blank = True)

so like in this example I need data from all models like if i need

#

empName , employeerole how can I do that?

devout coral
#

Employee.objects.all() will give you a query set which you can loop through all your objects. You can also filter. Or get first() and last()

haughty turtle
#

In my models I am storing my ImageField in STATIC_ROOT but I am having troubles accesing my images from CSS.

fs = FileSystemStorage(location=settings.STATIC_ROOT)
product_photo = models.ImageField(upload_to='product_images',storage=fs)```in my CSS I can access my static images placed in my Static folder by using ```css
background-image: url(Arrow_Left.svg);```but I am wanting to access my images stored in STATIC_ROOT trying```css
background-image: url(product_images/Arrow_Left.svg);```and ```css
background-image: url(../../../product_images/Arrow_Left.svg);``` but none of the two work
#

how would I be able to access these images and if not how can I store images from ImageField in my static folder, I have tried changing STATIC_ROOT to STATIC_URL and it did not difference

stable kite
#

@haughty turtle you cant store images from user as STATIC it should be stored as MEDIA

haughty turtle
#

where would that store it and how would I access it @stable kite

#

can you give an example

haughty turtle
#

MEDIA_ROOT and STATIC_ROOT must have different values. Before STATIC_ROOT was introduced, it was common to rely or fallback on MEDIA_ROOT to also serve static files; however, since this can have serious security implications, there is a validation check to prevent it.

#

Yeah I saw that before, but the warning made me think that STATIC_ROOT was the new default or something

#

@worn basin

stable kite
#

@haughty turtle no its for the static which are css,js,img only

haughty turtle
#

What is STATIC_ROOT? @stable kite

stable kite
#

@haughty turtle used for using statics for production

worn basin
#

iirc it's where everything goes when you run collectstatic as well

proper osprey
#

How would I get a selenium window to open in the background instead of popping up in the middle of my screen

native tide
#

not sure if this goes here

#

@proper osprey

proper osprey
#

im not sure where it goes tbh

#

Selenium is web but

devout coral
#

@proper osprey you need to add the option to open headless

proper osprey
#

How would I do that?

devout coral
#

Granted I have had some issues with it in the past when running headless.

#

Using chrome?

proper osprey
#

it's a pretty basic program, just clicks a couple buttons and then checks the html if a specific class exists

#

and yeah chrome

devout coral
#

Ok one sec

#

@proper osprey It should look like this:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(Path_to_chome_driver, chrome_options=options)
#

There are some other options too, to run incognito etc.

proper osprey
#

alright, thanks

#

wait, it gave me an error

#

DeprecationWarning: use options instead of chrome_options

native tide
#

thats a warning

#

but

shadow musk
#

Hello Django developers!

I have started to build an issue tracking system with Django and I'm checking if someone would be interested of developing/bring ideas etc on their spare time. It's not a serious project, it's just to practice and sharpen both Python and the Django skills. Perhaps someone would find the app useful and that would be a real bonus if that would lead to that in the future.

Please contact me if you are interested of programming with me on this project. The current repository is here at the moment: https://github.com/mjovanc/django-its

devout coral
#

@proper osprey just change it to options lol

#

@shadow musk You just started it seems. What is the vision for this?

rancid juniper
#

hello people,
I am trying to develop a django project. How can I make a http get request to another api ?

#

I am trying to interact with riots api

#

ı am a web development noob btw

#

but I can figur it out if I know which module to use?

quick cargo
#

use the requests module

#

or httpx

#

either would work as client based request systems

rancid juniper
#

thx

shadow musk
#

@shadow musk You just started it seems. What is the vision for this?
@devout coral Not a concrete vision atm. Just that I want to be a good alternative for setting up an issue tracking system in the Django admin area.

white spruce
#

CSS question here

devout coral
#

Shoot.

tardy briar
#

anyone here know the basics of parsing a homepage by any chance ?

#

or scrapeing it

devout coral
#

@tardy briar There are probably a lot of people. Have you ran into some troubles we could help with?

prisma nimbus
#

How come my css does not work when I use flask

acoustic oyster
#

@prisma nimbus I use django, but it should be similar in flask: make sure you are linking your css properly with some sort of static url. And that your file structure represents your imports and vis-versa

white spruce
#
 <section class="stories">
            <div class="container">
                <h2>Recent Stories</h2>
                <article>
                    <img src="man.jpg" alt="doctor">
                    <div class="article-body">
                        <h3>Dr. Christopher Turk has spent his entire career caring for people’s health and wellbeing.</h3>
                        <p>After years in the healthcare system, Dr. Christopher Turk is bringing together groups of people across the world to take on big healthcare challenges through groundbreaking research and developing tools that support better care.</p>
                        <p><a href="#">Read this Story</a></p>
                    </div>
                </article>
                <article>
                    <img src="virus.jpg" alt="covid">
                    <div class="article-body">
                        <h3>INFO2180 Labs collaborates with the Ministry of Health and Ministry of Education on COVID-19 Risk Screening and Testing</h3>
                        <p>INFO2180 Labs, in collaboration with the Ministry of Health and Wellness and Ministry of Education, will launch a pilot project intended to expand access to COVID-19 risk screening and testing for high risk individuals in the parishes of Kingston and St. Andrew.</p>
                        <p><a href="#">Read this Story</a></p>
                    </div>
                </article>
            </div>
        </section>
#

anyone, I am trying to get this image to show beside the text instead of below using css

#

I did this

article img{
    display: grid;
    float: left; 
    box-sizing: border-box; 
    width: 50%;
}
    
.article-body{
    float: left; 
    box-sizing: border-box; 
    width: 50%;
}
#

but it's not looking how I want it to look

#

anyone get any idea how I could do this or fix this?

#

anyone here?

stable kite
#

@white spruce change the size of your image & add some margin between both

white spruce
#

so my code is okay? I just got to add those and change the size

#

and add margin on images

#

thank you @stable kite made the changes

#
.testing .cta .btn{
    background-color: #48BB78;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    border-radius: 5px;
}
#

my css anyone

#
.testing .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 100px;
    width: auto;
}

this is what I did

#

code I am editing here

<section class="testing">
            <div class="container">
                <div class="testing-desciption">
                    <h2>COVID-19 Testing Programme</h2>
                    <p>Providing secure and connected COVID-19 screening and testing services to communities in collaboration with public health agencies and industry partners.</p>
                </div>
                <div class="cta">
                    <a href="#" class="btn">Learn More</a>
                </div>
            </div>
        </section>
#

anyone?

stable kite
#

@white spruce increase the width of your button

white spruce
#

dang, how did I miss that haha

#

thanks

#

what I code

<section class="newsletter">
            <div class="container">
                <h3>Sign up for our newsletter</h3>
                <p>Learn more about the latest developments from INFO2180 Labs’ health-related research and initiatives.</p>
                <form action="#" method="post">
                    <div class="form-group">
                        <input type="email" name="email" id="email" placeholder="Enter your email">
                    </div>
                    <button type="submit" class="btn">Subscribe</button>
                </form>
                <div class="message"></div>
            </div>
        </section>
#

trying to get my css to design it like that, any idea

#

anyone got anything in mind?

#

@stable kite got anything in mind?

#

if anyone got anything in mind for that css, I would appreciate it thanks

#
.newsletter{
    background-color: #48BB78;
}

.newsletter .container{
    color: white;
}

.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}
#

what I've done so far for the newsletter

#
.newsletter{
    background-color: #48BB78;
}

.newsletter .container{
    color: white;
}

.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}

input[type=email], select {
    width: 30%;
    padding: 15px 32px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
  }
#

update, so I did the button and input field. Anyone got anything in mind for getting it to look like that

#

this is what it looks like now from what I have done

#

anybody?

#

dang, everybody seems busy

stable kite
#

@white spruce try display flex

white spruce
#

I tried that @stable kite but I don't understand how I would get it to layout like that with flex

white spruce
#
.newsletter{
    background-color: #48BB78;
}

.newsletter .container{
    color: white;
}

.newsletter .container h3{
    display: flex;
    justify-content: center;
    align-self: center;
}

.newsletter .container p{
    display: flex;
    justify-content: center;
}

.newsletter .container .form-group{
    display: flex;
    justify-content: center;
}

.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}
#

I am getting close

wraith plaza
#

are you using a container for the input and button?

white spruce
#
<section class="newsletter">
            <div class="container">
                <h3>Sign up for our newsletter</h3>
                <p>Learn more about the latest developments from INFO2180 Labs’ health-related research and initiatives.</p>
                <form action="#" method="post">
                    <div class="form-group">
                        <input type="email" name="email" id="email" placeholder="Enter your email">
                    </div>
                    <button type="submit" class="btn">Subscribe</button>
                </form>
                <div class="message"></div>
            </div>
        </section>
#

yeah

#

but they aren't in 1 div

wraith plaza
#

try:

form{
    display: flex;
}
#

when you set display = flex, by default flex-direction is row

#

so display: flex should be enough

white spruce
#

so some of my stuff is unnecessary?

#

or I should just add that?

wraith plaza
#

what css code are you applying to style input and button?

white spruce
#
.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}

input[type=email], select {
    width: 30%;
    padding: 15px 32px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
  }
#
.newsletter{
    background-color: #48BB78;
}

.newsletter .container{
    color: white;
}

.newsletter .container h3{
    display: flex;
    justify-content: center;
    align-self: center;
}

.newsletter .container p{
    display: flex;
    justify-content: center;
}


.newsletter .container form{
    display: flex;
    justify-content: center;
}


.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}

input[type=email], select {
    width: 30%;
    padding: 15px 32px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
  }
wraith plaza
#

check this

#

you can set margin left on the button

#

to get the small gap

white spruce
#

did you change any html?

wraith plaza
#

nope

#

just css

#
.newsletter .container .form-group{
    display: flex;
    justify-content: center;
}
#

removed this

#

and added css for form and input at bottom of the file

swift knoll
#

i have a problem with webbrowser module

wraith plaza
#

its always good to post problems in codepen

swift knoll
#

my default browser is chrome yet it opens in ie

wraith plaza
#

its easier to tweak code and help

white spruce
#

I realize that, but not many people will come out of here to show stuff like that

swift knoll
#

can u just put a # b4 the channel where i can ask in this chat so that i can jump there \

white spruce
#

is my code just stubborn or what

#
.newsletter{
    background-color: #48BB78;
}

.newsletter .container{
    color: white;
}

.newsletter .container h3{
    display: flex;
    justify-content: center;
    align-self: center;
}

.newsletter .container p{
    display: flex;
    justify-content: center;
}

form{
    display: flex;
    align-items: center;
    justify-content: center;
}

.newsletter .container .btn{
    background-color: #5A67D8;
    border: none;
    color: white;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    border-radius: 5px;
}
#

still not giving me the full text field

wraith plaza
#

you want to make its width bigger?

white spruce
#

isn't that the width

wraith plaza
#

yes

#

set width in input

#

like width: 300px or something

#

I preffer to use %

white spruce
#

I went with the px

#

and got it

#

how much would you use

#

for %

wraith plaza
#

I guess its better to use a fixed width in this case

white spruce
#

how can I get a space between the input and btn

wraith plaza
#

set a margin right in the input

#

or left in the button

#

either works

white spruce
#

yeah, got it on the input

#

also on the text

#

what if I want my text like this

#

instead of right across

wraith plaza
#

well from your prototype

#

I think there is a container that wraps all your content right?

white spruce
#

yh

wraith plaza
#

so that container probably has a max width

#

I would set max-width in the wrapper container

#

and then the text would just wrap

white spruce
#

okay let me try that

#

about how much would you set it to

wraith plaza
#

idk man, check your prototype?

white spruce
#

our prototype is a image lol

#

I got it though

wraith plaza
#

guess 600px?

white spruce
#

actually did 100

#
.newsletter .container{
    color: white;
    justify-content: center;
    max-width: 100px;
}
wraith plaza
#

try 320px

white spruce
#

no difference on 320px

#

when the submission button is clicked I want to simulate a form submission

#

now I don't really got any javascript knowledge like that

#

how do I even start this lol

#

@wraith plaza thank you for that help also man

#

appreciate it

#

anything for that @wraith plaza ?

#
window.onload = function(){
    
}
#

who can give me some hope for this

gaunt marlin
#

@white spruce why do you need to use javascript to send a POST request form ? you can just do for as example

<form method="POST" action="/post-request-url">
# your csrf token
<input type="email" name="email">
</form>
white spruce
#

No @gaunt marlin

#

it is not gonna actually send

#

it's just a simulation when I press submit

#

for it to show some kind of activity that a form have been submitted

#

any idea on what I can do in javascript for that?

gaunt marlin
#

oh like an alert when you press the submit button ?

white spruce
#

completely new to js

#

yeah

#

I heard about some innterText or innerHTML stuff

#

so I guess sumn like that

gaunt marlin
#

you can access by DOM

white spruce
#

I am new to js but this is what I have been trying to do

#
window.onload = function(){
    const form = document.getElementById('form')
    const submission = document.getElementById

    form.addEventListener('submit', (e) => {
        let messages = []

        if (messages.length > 0){

        }
    })

}
#

something like that

#

I am not sure what I'm doing btw, just trying to understand

#

could you help on where to go from here

#

this is my form

 <section class="newsletter">
            <div class="container">
                <h3>Sign up for our newsletter</h3>
                <p>Learn more about the latest developments from INFO2180 Labs’ health-related research and initiatives.</p>
                <form action="#" method="post">
                    <div class="form-group">
                        <input type="email" name="email" id="email" placeholder="Enter your email">
                    </div>
                    <button type="submit" class="btn">Subscribe</button>
                </form>
                <div class="message"></div>
            </div>
        </section>
gaunt marlin
white spruce
#

something like that, only thing is I can't touch my html file

#

only allowed to modify js

#

can you show me what you would write

#

for sumn like this

#

I'm just learning js

gaunt marlin
#

then that probably hard without touching html because with javascript i can only think of onclick=function in html

#

other wise if you don't want to touch html, you can use jquery

white spruce
#

yup, no modifying of the html document

#

lol, I have no idea what you talking about

gaunt marlin
#

do you know about jquery ? @white spruce

white spruce
#

yeah

#

that handles the event clicks and stuff like that

#

a library

#

?

gaunt marlin
#

yeah it's like a javascript library

white spruce
#

oh I see

#

you got any other ideas

#

on how this could be written?

gaunt marlin
#

it's like so in the onclick function

#

you can still use your javascript code logic

white spruce
#

I want someone to try writing this, so I can understand since I am new to js

gaunt marlin
#

i don't think writing jquery will help much since you haven't learned jquery but i will give it a try

#
<script src="https://code.jquery.com/jquery-3.5.1.js" crossorigin="anonymous"></script>
<script type="text/javascript">   jQuery(document).ready(function(){
     jQuery('#form-id').on('click', '#submit-button', function(event) {
          event.preventDefault();
          var messages = []
          if (messages.length > 0){

          }
        });
</script>
#

@white spruce this should be the same as your but written in jquery for event handle

#

event.preventDefault(); is to stop the form from sending and reloading the page

white spruce
#

what would that say when clicked

gaunt marlin
#

@white spruce base on what ever you wanted, you can have alert box, message,...

#
window.onload = function(){
    const form = document.getElementById('form')
    const submission = document.getElementById

    form.addEventListener('submit', (e) => {
        let messages = []

        if (messages.length > 0){

        }
    })

}

@white spruce i only rewritten your previous one but with jquery

#

so this way you don't need to touch html

white spruce
#

haha I wasn't finished with that

#

I was just trying something

#

I am kinda trying sumn new

gaunt marlin
white spruce
#
/* Add your JavaScript to this file */
window.onload = function(){
    const form = document.getElementById('form')

    form.onsubmit = function(e){
        e.preventDefault();

        var result = document.getElementById('email');
        email.innerHTML = 'Form Submitted'
    };

}
#

can you help me to fix this, I think sumn like this should work

#

it brings

#

me to the top of the page though

gaunt marlin
#

it brought you to the top of the page because your form was submitted and it reloaded the page

#

you need event.preventDefault()

white spruce
#

I added that

gaunt marlin
#

oh nvm you already had that

white spruce
#

I just want it to show anywhere that form submitted

gaunt marlin
#

@white spruce does your url included # after you click the submit button?

white spruce
#

on action?

#

lol

#

just saw that

#
<section class="newsletter">
            <div class="container">
                <h3>Sign up for our newsletter</h3>
                <p>Learn more about the latest developments from INFO2180 Labs’ health-related research and initiatives.</p>
                <form action="#" method="post">
                    <div class="form-group">
                        <input type="email" name="email" id="email" placeholder="Enter your email">
                    </div>
                    <button type="submit" class="btn">Subscribe</button>
                </form>
                <div class="message"></div>
            </div>
        </section>
gaunt marlin
#

yeah it notified that your e.preventdefault() didn't work

#

@white spruce document.getElementById('form') but your form don't have id attribute <form action="#" method="post">

white spruce
#

oh I was gonna add it to see if it would work

#

but I never bothered

gaunt marlin
#

yeah it can't track the DOM in html

#

so it didn't run into your onclick logic

white spruce
#

I remember no modifying html

#

so

#

I don't know what else to do lol

#

any idea

#

on how to fix something there

gaunt marlin
#

@white spruce if it's the only form in your html you can access it with document.forms[0] in javascript

#

so it will be

const form = document.forms[0]
white spruce
#

yeah I did that

#

a while ago

#

still went for reloading

#

form[0]

gaunt marlin
#

forms not form @white spruce

white spruce
#

oh

#

nothing happens

#

now

#

so no reload

gaunt marlin
#

yeah

#

so it worked

white spruce
#

what about getting it to display

#

somewhere

gaunt marlin
#

inner html

#

you was using it right?

white spruce
#

yeah

gaunt marlin
#

where you want the message to show up ?

white spruce
#
window.onload = function(){
    const form = document.forms[0];

    form.onsubmit = function(e){
        e.preventDefault();

        var result = document.getElementById('email');
        email.innerHTML = 'Form Submitted'
    };

}
#

doesn't even matter lol

#

just want it somewhere

gaunt marlin
#

under email input?

white spruce
#

I wouldn't mind

#

that would work

gaunt marlin
#

you can get a div

#

and set it html to something like <p>submmited</p>

white spruce
#

lol

#

remember

#

no html touching 😄

gaunt marlin
#

maybe alert box ?

white spruce
#

I would have done that

#

oh what would i do for that

gaunt marlin
#

@white spruce alert("I am an alert box!");

white spruce
#

so remove

gaunt marlin
white spruce
#

email.innerHTML

gaunt marlin
#

yeah since you don't want to touch html right?

#

i don't even know which DOM you pointing to with email though

white spruce
#

yeah works now

#

email

#

was on

#

well that took some time

#

now got some small issues to fix

gaunt marlin
#

but remember the form not actually sending because you had preventdefault()

#

now if you want to send the form POST request it would probably required some jquery

white spruce
#

lol, only if we were sending some form

#

we not sending an actual form

#

haha

gaunt marlin
#

oh ok so you have a form but you not actually use it to send thing

#

got it

white spruce
#

yeah, kinda just getting a hang of css

#

this is what this is for

#

to get a hang of css and a little touch of javascript

gaunt marlin
#

you should learn jquery too after you learned javascript, it's really useful and used alot

#

to do interactive webpage

#

without reloading page

white spruce
#

yeah right after I am finish with this

#

I am gonna jump on some javascript

#

but I got some networking socket programming course

#

to do

#

so I wont have the time as yet

gaunt marlin
#

@white spruce w3schools is a really good site to learn for starter btw, it cover all the basics

white spruce
#

yeah that's where I have been going

#

to do this css

#

I only had the html

#

this morning

#

and I got it to a full page

gaunt marlin
#

oh i see

white spruce
#

with css

#

but still got some minor stuff to fix

#

running out of time

#

I wanna get that inline

#

any idea

gaunt marlin
#

i have no idea because i don't know about your course

white spruce
#

lol

#

no it's not a course

#

it's just a page

#

lol

#

it's still css

#
 <header>
        <div class="container">
            <h1>INFO2180 Project 1</h1>
            <nav>
                <ul>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Research</a></li>
                    <li><a href="#">Stories</a></li>
                    <li><a href="#">Partners</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </nav>
        </div>
    </header>
#

this isn't a course

#

this the css practice

#

and stuff

gaunt marlin
#

well i guess it's based on your time managing

white spruce
#

no

#

lol

#

it's a css

#

issue I am having

#

I was asking you

#

lool

gaunt marlin
#

oh then you can ask in here

#

what your css problem ?

white spruce
gaunt marlin
#

you should show your html and css codes

white spruce
#
.container {
    display: grid;
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}

header{
    background-color: white;
    font-size: 18px;
}

header h1{
    font-size: 18px;
}

ul{
    list-style: none;
    float: right;
 }

li{
     float: left;
 }
 
 li a{
     padding: 13px;
     color: #6b7280;
     text-decoration: none;
 }

 li a:hover{
     color: #5A67D8;
 }
#

that's what I was gonna do

#

what am I missing

gaunt marlin
#

do you use codepen ?

white spruce
#

heard about it last week

gaunt marlin
#

it's better to show it in there then pasting huge line of text

#

paste your html css code in code pen and share it with url

#

much easier

white spruce
#

can you edit my code pen?

#

or that doesn't work?

#

@gaunt marlin ?

gaunt marlin
#

@white spruce i'm not an expert on frontend so i don't know my method is ok but it worked on my side

.container {
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}
h1 {
  float: left;
}
nav {
  float: right;
}
#

change container and add float

white spruce
#

so what about ```js
header h1{
font-size: 18px;
}

ul{
list-style: none;
float: right;
}

li{
float: left;
}

#

not needed

#

?

gaunt marlin
#

yeah it's still needed

white spruce
#

lol

#

the whole code became a mess 😄

gaunt marlin
white spruce
#

maybe because I got additional stuff

gaunt marlin
#

probably

white spruce
#

like the divs started

#

going out of place

gaunt marlin
#

you should add id

#

h1 and nav will also affect every h1 and nav dom in html

white spruce
#

add id to what?

gaunt marlin
#

html

#

but i guess you can't

white spruce
#

yeah can't

#

think ama just leave that error

#

and take a L on that

gaunt marlin
#

so i guess you should use

.container {
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}
.container h1 {
  float: left;
}
.container nav {
  float: right;
}

try this @white spruce

#

so it only affect the container h1 and nav

white spruce
#

you see it works right

#

but the whole other

#

half of the code

#

gets thrown out of it's place

gaunt marlin
#

kinda hard to pin point since i don't know your entire html css

white spruce
#

yeah

#

ama add to codepen

#

check it now

gaunt marlin
#

oh i see

#

you have alot of div with the same class = "container"

white spruce
#

yeah

#

can't do much about the html @gaunt marlin

gaunt marlin
#

@white spruce here how i fixed it

main .container {
    display: grid;
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}

header .container {
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}

header .container h1{
  float: left;
}
header .container nav{
  float: right;
}
#

still hacky way

white spruce
#

am I removing anything?

gaunt marlin
#

only .container one

#

i just added main before container and create the second container css block which point to header

white spruce
#
header .container h1{
  float: left;
}
header .container nav{
  float: right;
}
#

and these new?

gaunt marlin
#

yes

white spruce
#

still kinda messes up

#

it goes into the grey div

#

and at the bottom copyright gets messed up

gaunt marlin
#

yeah i see that because of your margin

white spruce
#

it should be in the white

gaunt marlin
#

i didnt see the footer let me fix that

white spruce
#

aite

gaunt marlin
#

@white spruce here try this

main .container, footer .container {
    display: grid;
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}

header .container {
    padding: 20px;
    margin: 0 auto;
    max-width: 960px;
    width: 100%;
}

header .container h1{
  margin-top: 0px;
  float: left;
  
}
header .container nav{
  margin-top: -20px;
  padding-top: 0px;
  float: right;
}
#

, mean i will apply to both of those element

#

because you have 3 main element

<header>
<main>
<footer>
white spruce
#

oh it works, what if I want some margin at the top

#

text too close to the grey

#

or maybe some padding anyone

#

oh I see

#

what you saying

gaunt marlin
#

@white spruce apply to your header css

header{
    background-color: white;
    font-size: 18px;
    padding-bottom: 30px;
}
#

padding-bottom push header div's bottom so it take more space

white spruce
#

woo that worked

#

also you see the part in the cards

#

with the h3 tags

#

they should have been inlined

#

struggled with that so I left it

gaunt marlin
#

it look ok to me ?

#

the card part

white spruce
#

yeah

#

you see

#

when images are added there

#

the headers are no longer inline

gaunt marlin
#

i dont have the image so it doesnt show anything for me lol

white spruce
#

lol yeah

#

only thing that's missing from codepen I guess lol

gaunt marlin
white spruce
#

haha

#

because you added 3 images of same size

#

if they different size they wont be like that

#

dang

#

so that's the hack i MUST USE

#

:d

#

about to change all my images to that size 😄

#

send me that image

#

good idea to get around the system

gaunt marlin
#

you can set image size with width and height

white spruce
#

the images

#

when I did that

#

they all wouldn't be the same size

#

when I changed the width and height of them all at once

gaunt marlin
#

that why you can set it

#

so it the same size

white spruce
#

would I have to set them individually?

gaunt marlin
#

you can target it's class parent img

#

the parent class is learn-about

#

so @white spruce

.learn-about img {
   height: 100px;
   width: 100px;
}
white spruce
#

and all my image would have been set the same?

gaunt marlin
#

yeah

#

all the image in the dev with class = "learn-about"

white spruce
#

gonna try to find a size that fits the card

gaunt marlin
#

probably 300px width and height is the perfect size

white spruce
#

yeah that's an issue

#

doesn't fit perfectly

gaunt marlin
#

you can modify the px until you find satisfied

white spruce
#

don't like how it stretches my images though

#

don't give it that same look

#

maybe because your images are all the same size

naive crater
#

what's wrong with this:

{% for value in values %}
  {{set class = map[loop.index]}}
  <div class=class><b>#{{loop.index}}: {{value[0]}}</b><br><i>Level: </i>{{value[3]}}<br><i>Messages: </i>{{value[1]}}<br><i>XP: </i>{{value[2]}}</div>
{% endfor %}```

If map = `{"1": "one", "2": "two", "3": "three", "0": "zero"}`?
here's the error
```py
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'class'```
#

please ping me if you know I'm so confused 😐

tall plaza
#

@tall plaza check this out
https://stackoverflow.com/questions/21945796/how-can-i-use-two-different-model-serializers-with-the-same-model
@stable kite yeah i resolved that problem by just provide base name in urls. damn i did not know that it was so easy

ashen trench
#

I am having trouble understanding what i'm doing wrong here

I am trying configure the permissions for my API calls using the Django Rest Framework but its not working.
I am still able to access the data with a token associated to a user object which does have any permission on the model.

According to the documentation, setting DjangoModelPermission should take care of the issue. https://www.django-rest-framework.org/api-guide/permissions/#djangomodelpermissions but that's exactly what i am doing.

#
    'DEFAULT_PERMISSION_CLASSES': (

        # 'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.DjangoModelPermissions',
    ),```
#
class UserDataView(APIView, ResponseMixin):
    model = User
    serializers = UserDataSerializer
    queryset = User.objects.none()

    def get(self, request, user_id=None):
        if user_id is not None:
            queryset = get_object_or_404(self.model, id=user_id)
            serializer = self.serializers(queryset)
            return Response(serializer.data, status=200)
        else:
            queryset = self.model.objects.filter(verified=True).order_by('-perks')[:20]
            serializer = self.serializers(queryset, many=True)
            return JsonResponse(serializer.data, safe=False, status=200)```
#

here is an example of one of my views

#

note: the User is not the default django User

stable kite
#

@ashen trench I think by default the user has permission to get & post data.

#

you manually need to change it

ashen trench
#

right now i've created two users, one is a superuser and other one is normal user (has no permissions on any models).
and generated tokens for both users... But still i am able to access all data with both the tokens

stable kite
#

right now i've created two users, one is a superuser and other one has no permissions on any models.
and generated tokens for both users... But still i am able to access all data with both the tokens
@ashen trench normal users also have permissions

#

the only difference is super user can access admin interface

gaunt marlin
#

you can check if the user data has that permission to confirm it first

UserInstance.user_permissions.all()
ashen trench
#

@stable kite i'm not sure if you know normal users can also access the admin interface. the superuser has all permissions by default while we have to specify permissions for normal user while creating them.

south lodge
#

Does anyone know if it's possible to upload multiple binary files to Imgur in a single POST request using their API? Their apidocs only shows how to upload a single file and leaves the files = [] empty.

gaunt marlin
#

@ashen trench in default user model there an is_staff column to determind if user can access the admin

ashen trench
#

yes

#

i know about that

gaunt marlin
#

have you check if your user has is_staff = True or False ?

ashen trench
#

is_staff has nothing to do with the permission on models, it just specifies if the user has permission to login to the admin panel. And yeah that option is not checked as i am not planning to login.
I just want to restrict access to certain models for each tokens.

stable kite
#

@ashen trench try this

'rest_framework.permissions.DjangoModelPermissions', 'rest_framework.permissions.IsAuthenticated',
    ],```
ashen trench
#

i tried that as well

#
REST_FRAMEWORK = {

    'DEFAULT_AUTHENTICATION_CLASSES': (

        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (

        'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.DjangoModelPermissions',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
    )

}
stable kite
#

it should be a list

ashen trench
stable kite
#

i know

ashen trench
#

are you sure ? what's the difference

native tide
#

@ashen trench In your view you need to state the permissions / auth that that view has

#

Here's an example...

#

You have to import authentication_classes and permission_classes which will authenticate an incoming request. Since you're using token auth your request needs a token header too...

#

This is for function-based views anyway

#

For class based views it's a bit different, think it's a list

ashen trench
native tide
#

Yeah but I'm not talking about your settings.py. You don't have any auth classes or permission classes in your view.

This is your view:

class UserDataView(APIView, ResponseMixin):
    model = User
    serializers = UserDataSerializer
    queryset = User.objects.none()

    def get(self, request, user_id=None):
        if user_id is not None:
            queryset = get_object_or_404(self.model, id=user_id)
            serializer = self.serializers(queryset)
            return Response(serializer.data, status=200)
        else:
            queryset = self.model.objects.filter(verified=True).order_by('-perks')[:20]
            serializer = self.serializers(queryset, many=True)
            return JsonResponse(serializer.data, safe=False, status=200)```
gaunt marlin
#

you don't need to specify if it already listed in default auth of settings

native tide
#

but... you do

ashen trench
#

?

gaunt marlin
#

you only use authentication decorator on view if those views has some special authentication_class that other don't use

#

in this case if you set defaults authentication class in settings, if you want to use it you don't have to list it again

native tide
#

that's strange, when I was doing my API views - although it was globally set, I had to set it for each one.

#

So how would you go about having an API endpoint without authentication?

gaunt marlin
#

he had authentication

#

it's in his setting

native tide
#

Yeah I know.

#

So how would you go about having an endpoint without auth?

gaunt marlin
#

@native tide if you read the docs, if you don't list in the settings or view then DRF will use BasicAuthentication and SessionAuthentication as defaults

native tide
#

Yeah... But I'm talking about if you do list it in settings

gaunt marlin
#

then you use that authentication class instead of the default one

native tide
#

But what if you don't want auth on that endpoint... that's the question

#

actually I can answer that anyway

#

That's from the permission class

gaunt marlin
#

you can authentication_classes = () if you don't want any

native tide
#

isAuthenticated

ashen trench
#

okay i just tried printing out print(request.user.has_perm('tortoise_api.add_user'))

#

and it gives false and true for the corresponding users

#

so the problem is not at the database level

native tide
#

@ashen trench also shouldn't your settings be in a list not a tuple

#
REST_FRAMEWORK = {

    'DEFAULT_AUTHENTICATION_CLASSES': (

        'rest_framework.authentication.TokenAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (

        'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.DjangoModelPermissions',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework.renderers.JSONRenderer',
    )

}```
ashen trench
#

I mean is it necessary?

#

tuple works fine

native tide
#

hmm ok

#

I never knew you could use tuples

gaunt marlin
#

most of django functions accept both list and tuple

ashen trench
#

basically DjangoModelPermission is not working for me because of something i did wrong somewhere

sudden grail
#

Hey guys, Can i have some feedback? I love coding in pyhon/django and i thought about visualizing this process for non-technicals or for teams to build faster apis.
It would be a browser based tool, and will generate well structured django apps.
Makes sense?

tall plaza
#

i am unable to create app name in Heroku

#

i am getting some error

#
    at ClientRequest.onError (C:/Program Files/heroku/client/node_modules/tunnel-agent/index.js:177:17)```
mystic spindle
#

Any suggestions for learning Django if I have experience with other languages and web dev frameworks? (Specifically my last web dev job was Ruby/Rails).

sudden grail
#

NOTE: Updated and compatible with Django 3.0

In this video I'll introduce my django crash course series. In these tutorials we will will be building a customer management app. Part one will cover installing django and getting our basic app setup.

Follow me on Twitter: https:...

▶ Play video
fleet bear
#

Hey Django guys :D

Quick question, I'm looking forward the doc to implement my own button + action to generate bunch of objects, I want to place it near to the "Add tagged articles" button from that screenshot : https://i.stack.imgur.com/iP6sm.png

stable kite
fleet bear
#

Thanks, that should do the trick ;)

shut marten
#

hi

summer wyvern
#

Hi, I would like to create buttons and a input to create a Password generator on Django and then connect it to python functions, so it can generate the passwords. I have already programmed the password generator, and only need help with setting up the website. Thanks, Famous8

native tide
#

@summer wyvern Ok, very simple, what seems to be the issue?

summer wyvern
#

no issue

#

I haven't created it yet

#

@native tide

native tide
#

need help with setting up the website.

summer wyvern
#

I have some basic knowledge of Django

#

but I dont know how to connect buttons and inputs to python functions

#

as they are created with html

native tide
#

are you familiar with django templates

summer wyvern
#

no

native tide
summer wyvern
#

I have been given that link so many times

#

is there a video?

#

that goes over the forms

native tide
#

thats up to you to find

summer wyvern
#

ok

native tide
#

but that doc goes through every step

summer wyvern
#

ok

native tide
#

so its a good resource

swift sky
#

how does flask handle file uploads

#

im trying to upload an xlsx file to mysql

#

or am i supposed to write a mysql query to load the data and trigger the query somehow

polar trellis
#

in general you would save the uploaded file somewhere and store the path to the uploaded file in the database

swift sky
#

and then use mysql to query that path

mystic spindle
#

@mystic spindle https://www.youtube.com/watch?v=xv_bwpA_aEA&list=PL-51WBLyFTg2vW-_6XBoUpE7vpmoR3ztO and the whole series by him
@sudden grail Thank you! 🙂

NOTE: Updated and compatible with Django 3.0

In this video I'll introduce my django crash course series. In these tutorials we will will be building a customer management app. Part one will cover installing django and getting our basic app setup.

Follow me on Twitter: https:...

▶ Play video
polar trellis
#

yes then you could use mysql to find the path to the file

swift sky
#

i assume this is the lib

polar trellis
swift sky
#

porque no los dos

#

ok thx

#

🙂

summer wyvern
#

@native tide Every time I run the server I get this error ```py
path('hello/', name),
NameError: name 'name' is not defined

native tide
#

name is the name of your view. Do you have a view?

bronze blaze
#

good morning, I have a question

summer wyvern
#

?

#

I dont understand

native tide
#

@summer wyvern ok, so can you explain what you think this code that you wrote means?
path('hello/', name)

summer wyvern
#

I followed the tutorial and it worked fine

#

but that was with index.html

#

and I replaced it with name

#

and it doesnt work

native tide
#

path works like this: path(url, view)

#

and the view is the function which runs when you reach that url

summer wyvern
#

?

native tide
#

you don't render html in the path variable

summer wyvern
#

oh

#

ok

#

so I put the view name instead?

native tide
#

where you typed name it should be a view

#

yea

summer wyvern
#
from django.http import HttpResponseRedirect
from django.shortcuts import render

from .forms import NameForm

def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = NameForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            return HttpResponseRedirect('/thanks/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = NameForm()

    return render(request, 'name.html', {'form': form})

bronze blaze
#

is it necessary to have a 64bit system in order to use flask?

summer wyvern
#

I dont think so

#

32 bit should work

bronze blaze
#

nice, thank you very much

summer wyvern
#

im not familiar with flask

#

but it should work

native tide
#

as long as you got a cmd you can run flask lmao

summer wyvern
#

yep

#

it shouldnt need a lot of power

bronze blaze
#

I don't have cmd, I have terminal

native tide
#

same thing

summer wyvern
#

yep

#

same thing

bronze blaze
#

nice

summer wyvern
#

what is the name of my view?

native tide
#

get_name

summer wyvern
#

ohhh

#

ok

#

I understand now

native tide
#

then in your template (html file) you can render that form, then in your view you can access the input and do whatever you want w it