#web-development

2 messages ยท Page 45 of 1

rustic pebble
#

So I guess I should make an empty html with the file on it

tired root
#

Just put the file into a temporary directory and show a download link

rustic pebble
#

and redirect the user to it

tired root
#

that is the easiest method

rustic pebble
#

Or that

#

thanks man

#

I have been stuck on that for some time

#

:0

tired root
#

Well, I love simplicity

rustic pebble
#

I love making things work

#

I learned python, js, css html, etc

#

4 months ago

#

and now I am building websites every week

#

it is amazing

tired root
#

I know a bit of that

rustic pebble
#

Haha ๐Ÿ˜›

tired root
#

If you look at my status, I've made that in ~2 hours

rustic pebble
#

In summer I will try to participate into the coding contest here, I hope it is web related!

tired root
#

(using particles.js)

rustic pebble
#

Nice

#

I like js it is very very practical

blazing compass
#

Hey any1 tell me how much estimate it take to run a django website of raw material related businesses any idea?

native tide
#

Do you mean how to make site, or how long for user to load site?

You can make a site pretty quickly. I think it depends on how well you know framework and the specific plan for site.

#

I just started with class based views. It's amazing how much it can build for you in just a few lines.

#

TBH, it makes me feel cheap, like its doing all the work haha

spare canyon
#

is anyone familiar with nadex? or binary options? im trying to figure out how i would go about finding the formula for figuring out the price of the contracts for each strike (without the data being live), previous price history doesnt exactly help

#

closest ive found is black scholes model (i think this is only for spreads though)

rustic pebble
#

Anybody familiar with send_from_directory I am using it like that:
return send_from_directory(app.config['UPLOAD_FOLDER'], 'accounts.txt')

#

Both upload_folder and accounts.txt exist, I am not getting errors but the file doesnt get sent from the server to the client

rigid laurel
#

Are you sure the client isn't receiving it in a form it doesnt expect? have you tried checking the network tab in chrome/ff to see what it actually receives

#

normally these errors are mimetypey stuff

rustic pebble
#

I am aware that there should be some kind of receive function on the client-end but I am yet to find somewhere explaining how I should make it

rigid laurel
#

well, receiving it should just be a normal request

#

have you tried making it in postman or similar?

rustic pebble
#

This is the reply I am getting on the client end

rigid laurel
#

You're just sending a .txt right? not a json?

rustic pebble
#

Yup

#

let me try sth else

rigid laurel
#

If so, at some point you're trying to parse that .txt to a json

#

you probably need to fiddle with your fetch function to nor always parse to json

rustic pebble
#

let me try

#

I changed it to not give out json

#

This is the reply I am getting

rigid laurel
#

thats what you'd expect I assume?

rustic pebble
#

Yea but I need it to download the file

#

I understand that the response says everything is okay

#

I wrote it

#

But I am not sure on what to do to initiate a client sided download when they click the appropriate button

rigid laurel
#

are you getting the file via ajax?

rustic pebble
#

fetchapi

rigid laurel
rustic pebble
#

Oh damn

#

Why is it that difficult

rigid laurel
#

yeah, the content-disposition is what I've used before actually

#

I forgot that was a thing

#

flask's send file has an as_attachment (or something) paramater that you can pass

#

You will still have to change your ajax function at least a bit

rustic pebble
#

Hmm

#

I am using fetch not ajax

#
async function postData(url, data) {
        count += 1;
        if (!reached) {
            const response = await fetch(url, {
                method: 'POST',
                mode: 'cors',
                cache: 'no-cache',
                credentials: 'same-origin',
                headers: {
                    'Content-Type': 'application/json'
                },
                redirect: 'follow',
                referrerPolicy: 'no-referrer',
                body: JSON.stringify(data)
            });
            return await response.json();
native tide
#

I was reading about fetch after our talk yesterday. I used it to grab some json. I need to read a book on JS. That's how I learn. I know some people say that's a waste of time but its not for me. Thoroughly reading books is how I got half decent with Python. If I want to be even close with JS, I have to do the same.

#

its mainly the HTTP stuff that I need to know better.

rustic pebble
#

Not really, you will find learning js quite easy if you have a good knowledge of python

native tide
#

You dont use python in a browser to do http

#

WEll I mean

#

Lately I have been lol

#

But I dont have a lot of experience with that

rustic pebble
#

You only learn smth when you really need it

tired root
#

Python is like PHP basically

#

a server-side language

native tide
#

True.

rustic pebble
#

^^

native tide
#

Yeah, I get that.

tired root
#

@rustic pebble You are getting that error because the content is either not a json or the variable == null

rustic pebble
#

I know

#

I am just not sure how to receive that object

#

I think I got it figured

#
 fetch(url, options)
  .then( res => res.blob() )
  .then( blob => {
    var file = window.URL.createObjectURL(blob);
    window.location.assign(file);
  });
#

I will use smth like that

native tide
#

what is a blob?

rustic pebble
native tide
#

a file object then

#

interesting

rustic pebble
#

Yup

native tide
#

Ive never seen that syntax youre using above before but i sort of read it

#

JS has too many syntactic variations

#

arent you not supposed to use var anymore?

#

I dont remember why

rustic pebble
#

let is better

native tide
#

mm

rustic pebble
#

let is function scoped whereas var is global scoped

native tide
#

thats right

tired root
#

Always try to avoid globals where you can

#

It's not always possible though

rustic pebble
#

yup

native tide
#

So being a part of this greater community before I started focusing on webdev and came in here... I didn't realize that this might be an acceptable place to talk about JS. Is that generally frowned upon here? Or is it accepted as a part of web dev we can't ignore?

#

Right

#

I get that

tired root
#

I don't think anyone minds

rustic pebble
#

Anyways do you think what I typed is okay? @tired root

#

You can talk about it

native tide
#

fair

tired root
#

Don't ask me, I am inherently bad with JS

rustic pebble
#

Haha

#

What do you use for frontend then?

native tide
#

I am planning to get better at it and this community is the best programming community Im in

#

So... I'll probably be in here with JS problems eventually haha

rustic pebble
#

Haha good, this community is good because the staff is active enough to be able to moderate it

native tide
#

For sure.

tired root
#

Well, JS

#

what else

#

I often try to use TypeScript

rustic pebble
#

I have never even tried reading typescript

tired root
#

it makes things a bit better for me, because it is strongly typed and has a better syntax

rustic pebble
#

Is it easier than js

#

?

tired root
#

It writes like js, but with a more strict typing and allows for oop in classes etc

#

And at the end, it is only generating js

native tide
#

I've used typescript compiler to get error messages out of my JS...

rustic pebble
#

Hmm, I will give it a shot then. I really like js, it is very amusing when it works haha

native tide
#

But I have never looked into specifically TS syntax

tired root
#

I started using it when I did a small game with Phaser.io

rustic pebble
#

Usually I add way way too much javascript to make everything as dynamic as possible

#

I am thinking of switching to desktop apps with electron or react

#

and python backend

tired root
#

be careful that your site still works when the user disables js

native tide
#

That might be interesting. The main reason I decided to make web apps is because I want to make things that people will look at eventually, particularly people who are not programmers.

#

It just made sense

rustic pebble
#

Who disables javascript? omg

native tide
#

I disable JS all the time.

#

lol

rustic pebble
#

Why tho

tired root
#

A lot of people disable javascript

native tide
#

Because its often manipulative and shitty

tired root
#

Because it can be dangerous

native tide
#

It depends on where you go

#

I whitelist

tired root
#

For example, some people disable back in history with js

#

not allowing you to leave their site

rustic pebble
#

I usually have dynamic elements that are loaded from querying my database through the server

tired root
#

That is an instant blacklist for me

rustic pebble
#

So if people disable js they wont be able to view core functions of the website

tired root
#

That is bad design

native tide
#

Yep. Thats why if you want people to use your site you should use noscript lines

tired root
#

Go on Reddit and disable javascript

#

The site will still work

rustic pebble
#

For example say I have a count saying Total Users this means it will send a request on my flask server the flask server will do the calcs and display it to the user

#

using js

#

If they disable it its just going to be empty

native tide
#

Sites are moving towards not supporting people who block JavaScript more and more but the reason why is that...

tired root
#

ok barely lol

native tide
#

They are not able to profit in the manipulative ways that they do otherwise

#

my opinion is F em

rustic pebble
#

How is it manipulative using dynamic elements

#

Wow you really have got javascript wrong..

native tide
#

There is nothing innately wrong with it. It can be used in a shitty way or in not.

rustic pebble
#

Everything can be used in ashitty way

#

What is the point of having backend support at all then since the server can see your IP

native tide
#

Yeah, and I exercise control over what I run on my computer to deal wioth that.

#

Thats why I dont let any webstie I visit execute JavaScript at their whim

rustic pebble
#

Hmm

#

I dont disable js because I am not really visiting many websites except of stackoverflow, reddit, discord and facebook

#

And I have a mac for daily use which means I have added security on some parts

native tide
#

Its not dynamic animations and interactivity I have a problem with

#

Its following me across the internet

#

Its a personal choice

#

I dont think everyone has to do what I do.

#

But you should keep in mind that

#

there are a lot of people who block JS by default

#

thats why people use noscript lines

rustic pebble
#

Blocking js is like getting a car and disabling all electronic devices

#

I have noscript/mock lines in all my websites

#

but it just doesnt look that nice

#

I am getting back to python now, thanks for the chat

native tide
#

That's exactly what I do in a car lol.

#

Nah, jk

#

But I dont care for smart devices or anything like that.

#

Basically though, as the type of user I am talking about...

#

If you have a site the relies on interactivity because its more like a game or something.

#

You can use noscript lines to tell a user like me what your site is about

#

And I will very likely whitelist you.

#

And check you out.

#

But by defualt

#

I prefer not to

rigid laurel
#

I have 0 sympathy for people disabling JS - if you're worried about being tracked, block it in more effective ways

#

honestly I just see it as pretty dumb

#

most of the modern internet relies on JS heavily - and thats fine

native tide
#

It does and it is tedious. But... when you use the same website fairly frequently.

#

Eventually you have listed the ones you want to allow JS from.

#

And its not a big deal

#

I dont know why people insist on condescending to people for their choices really.

#

It would be different if I was in here waging a campaign of, "You guys all need to block JS today."

#

But Im not. I know that what I do is fringe.

#

And if you don't want to accomodate me thats fine

rigid laurel
#

I see it as akin to someone putting crystals all over their house for the healing power - you can do it, it doesn't harm me, but I still think its silly

rustic pebble
#

Well blocking js is blocking the biggest part of a webapp

#

Like I have spent around 3 days now building the js relay

#

If someone were to disable it they would just be dumb asf

native tide
#

I agree with you about the crystals.

#

I'm not paranoid or anything. I just like to pay attention to what's going on.

#

Like I said, after look at what your page is, I'd likely whitelist it if there was no sign of something I dont like.

#

There are often things I dont like in my browser as a result of JS

#

If you think Im dumb af for changing things I dont like for my purposes....

#

then fine.

#

Its an unnecessary amount of "You're stupid" that gets thrown around for things like this.

#

I almost dont even like to talk about it because of it.

#

I try to be as, "This is just what I do, I understand that there is no need for you to do this, you dont care about this, that's fine"

#

No effect

#

People are equally assholes to me about it.

rustic pebble
#

@native tide When you start spending hours trying to get something to work you will start appreciating javascript, developers spend days trying to create an optimal and secure client-server connection and people who disable js are just straight up shitting on their face

restive kindle
#

stop crying

rustic pebble
#

right

native tide
#

...

#

People are not required to use your software.

rustic pebble
#

If they visit my website then it is their choice to use it

native tide
#

I have things to do today.

rustic pebble
#

Like it is contradicting, why visit a website where you only want to view a part of it?

#

๐Ÿคทโ€โ™€๏ธ

marsh ginkgo
#

Has anyone received "WSGI script cannot be loaded as Python module" and "ModuleNotFoundError: No module named 'project'" before? Running Django with apache2 on Ubuntu 18.04. I have spent 8 hours trying to solve this without any luck. Willing to offer a token of appreciation through PayPal if anyone could help me fix this. Worked just fine before a new deployment and sudo apt-get update. Logs: https://stackoverflow.com/questions/60573638/django-wsgi-script-cannot-be-loaded-as-python-module

tired root
#

have you checked the status of selinux?

#

just type getsebool and it tells you

#

@marsh ginkgo

marsh ginkgo
#

Hi again @tired root, as you can tell my wipe of the server as mentioned in DM didn't work ๐Ÿ˜‰

#

getseebool returns "Command 'getsebool' not found

#

I will install it

tired root
#

NO

#

it's fine

marsh ginkgo
#

Then I won't ๐Ÿ˜„

tired root
#

SELInux is a beast to tackle

#

but if it is on, it can cause issues like this

marsh ginkgo
#

I see

tired root
#

It's basically something like Windows security policies for Linux

#

WSGIScriptAlias / /var/www/project/myapp/wsgi.py

#

Yesterday you said it is in /var/www/project/project

marsh ginkgo
#

Ehm, let me check here. Modified the names just for Stackoverflow lol

tired root
#

yeah, in the logs it also says project/project

marsh ginkgo
#

Sorry, that was incorrect when I changed the name for stackoverflow. I am indeed using the right one. /var/www/project/projec/wsgi.py

tired root
#

what's the group on the wsgi daemon?

#

and is that group assigned to apache as well?

marsh ginkgo
#

What do you mean by group?

tired root
#

nvm I thought it is something else

#

but in your WSGIDaemonProcess you don't specify a user. I wonder if it runs with the www-data group by default then

marsh ginkgo
#

Good point, I will try specifying a user

tired root
#

Well, don't if you don't have to

#

I am not quite sure

#

I don't configure apache that often

marsh ginkgo
#

Worth a try, but Apache didnt like it

tired root
#

Well, the whole process runs as that user then

#

with the group

#

I just did it for added security

#

If this option is not supplied the daemon processes will be run as the same user that Apache would run child processes, as defined by the User directive, and it is not necessary to set this to the Apache user yourself.

#

so if the the directories are owned by www-data or however the user is called on Ubuntu it is fine

marsh ginkgo
#

Stupid questions perhaps, but any easy command to see that?

tired root
#

can you check the apache logs?

marsh ginkgo
#

I used whoami but not sure if that is correct

tired root
#

in var/log?

#

no

#

groups www-data to see apaches group

marsh ginkgo
#

To see if the directories are owned by www-data

tired root
#

ls -la

#

some distris also specify the ll alias for that

marsh ginkgo
#

Same error message as in the url above ๐Ÿ˜ฆ

tired root
#

Have you checked the apache error log?

#

/var/log/apache2/error.log

marsh ginkgo
#

Yeah, same error message

#

As in my stackoverflow thread

tired root
#

nvm I am stupid, that was that log ๐Ÿ˜„

marsh ginkgo
#

Hehe

#

Thx a lot for your help so far

tired root
#

I mean, I can find a lot of threads about it

marsh ginkgo
#

Really appreciate it

tired root
#

but no solution

marsh ginkgo
#

yeah same here...

tired root
#

go to the directory, enable venv

#

where your project is

#

then just type import django

marsh ginkgo
#

I am not using a venv

tired root
#

oh

marsh ginkgo
#

I tried to before, but thought it was easier to just go global on this VPS

tired root
#

I think it would be better to create one and give apache the rights to it

#

you can create a venv in the same directory as the project

#

This is how I do it:

import sys

activate_this =  "/home/wsgi/.local/share/virtualenvs/radio/bin/activate_this.py"
exec(open(activate_this).read(), dict(__file__=activate_this))

sys.path.insert(0, '/var/www/html/radio')
from backend import backend```
marsh ginkgo
#

Maybe try to use nginx

tired root
#

But I run apache for python with a different user

#

@marsh ginkgo a quick test would be to enable www-data for login, create a proper home, su - www-data, install the files with pip and see what happens.

#

If you have installed the packages as root, the child process of apache can propably not read them

#

that is why a different user with a venv would be better

#

Or only a different user for the wsgi process

#

install the packages as said user

marsh ginkgo
#

Aah I see, I Installed everything with sudo

#

But, weird thing still is that it WORKED before an deployment and an sudo apt-get update...

tired root
#

WSGIDaemonProcess backend.wsgi user=wsgi group=users threads=1

#

example

tranquil robin
#

I have been checking some different django applications and I am seeing two different conventions for including an app in the django project.
some add blog.apps.BlogConfig others add blog to INSTALLED_APPS in settings.py.
Can someone explain to me what the different is, and if there is a preferred method?

rustic pebble
#

Does anybody have experience with this?

native tide
#

Dont know if this is the place but

  payload = {
  "embeds": [{
      "title": "Title"}]}

  headers = {
  'Content-Type': 'application/json'
  }

  requests.post(url = "[redacted]", data = payload, headers = headers) 
``` im trying to post this to webhook, does anyone know why its not sending
#

if this isn't the place point me to the channel

rustic pebble
#

this is for discord?

native tide
#

yea

rustic pebble
native tide
rustic pebble
#

What is it then?

#

First of all as a url I can see you are sending the string ['redacted']

native tide
#

because im not sending the webhook token

rustic pebble
#

URL is for sure 100% wrong

#

The rest should be fine, I have no experience with discord webhook though but this doesnt seem any different from normal requests on python

native tide
#

https://ptb.discordapp.com/api/webhooks/{channelid}/{webhookpassword}

#

this is what im passing

#

for url

rustic pebble
#

not really

#

what you are passing is this: "[redacted]"

#

Does anyone know how to get over this:

has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
tired root
#

yeah, you need to do a proper cors request

rustic pebble
#

I am doing this:

#
def filesendhandler():
    file_for_sending = send_file("./uploads/accounts.txt", mimetype='text/plain', as_attachment=True, conditional=False)
    file_for_sending.headers['x-suggested-filename'] = "accounts.txt"
    file_for_sending.headers.add('Access-Control-Allow-Origin', '*')
    return file_for_sending

#

But this doesnt seem to be working properly

#

I have also added it as headers on my client side request

#
let response = await axios.get('/textaccsrequest', {headers: {'Access-Control-Allow-Origin': '*'}});
tired root
rustic pebble
#

Hmm

#

Question: What should I add between these: ...
app = CORSMiddleware(make_app(...), "http://example.org/")

native tide
#

I know that I'm gonna be in here trying to fix problems withs cors sooner or later. In fact I already know the problem with cors that is waiting for me. I'd love to know what to do about it, personally haha

rustic pebble
#

Well tbh there is a plugin called flask_cors

#

And you can wrap your app in cors using CORS(app) but for me it doesnt work this time

#

:/

#

I have written a script to receive, transcode and send the files to user on js

#

And it needs cors to work correctly

native tide
#

I'm getting to learning Django's "generic" class based views, which seem a lot simpler and are easy to write and save you a lot of work. But as soon as you want to customize them, it basically a lot of... writing over a parent method or attribute somewhere that you have to look up.

class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
    model = Post
    fields = ['title', 'content']

    # write over the parent form_valid method
    def form_valid(self, form):
        # the form you are submitting takes the instance and sets the author to the current logged in user
        form.instance.author = self.request.user
        # run the parent form validation with the adjusted form passed in
        return super().form_valid(form)

    def test_func(self):
        # gets current post object -- checks if logged in user is author
        post = self.get_object()
        # logged in user in request checked against post's author
        if self.request.user == post.author:
            return True
        return False

Obviously its going to save a lot of work for views that involve saving, updating, deleting, listing, etc. Typical posting type stuff.

But I'm not sure I like how much its just a lot of inheriting this and writing over methods that a lot of times its confusing to understand what they are even doing. Thats why Im commenting every line for now until I understand it.

#

Thats just an example not a question

#

Ive never heard the word "Mixin" until now

native tide
#

Is there a way to prevent users from viewing static files

#

in flask

rigid laurel
#

what exactly do you mean? @native tide

native tide
#

Like when a user tries to view static files

#

Like css files @rigid laurel

rigid laurel
#

well

#

assuming you want your css to be applied to your HTML

#

then the user needs to have access to the CSS so its not really possible no

#

I'm also not sure why you'd want to do that

native tide
#

Its possible in basically every platform

rigid laurel
#

there is no platform

#

that lets you not have public css

#

whilst applying said css to html

#

thats just not the way css works

rustic pebble
#

maybe you mean apps like electron?

native tide
#

thats how it works in apache

#

lmao

rigid laurel
#

If CSS is being applied, then the CSS file has been requested by the client

#

then the client applies the css rules to the HTML

native tide
#

but it hides the endpoint for static files

#

and returns 403

rigid laurel
#

๐Ÿ‘

native tide
#

So theres no way possible at all?

#

There is no way at all.

#

Btw

#

I have a base template in Django for pretty much every page on the site. I would like to have a conditional in that template that is something like {% if <the current page is url named 'this-page' in conf> %}

#

But I dont know how to say that in DTE

#

Basically like, I want to have something included in the base page template but only if current url is one of these urls

#

There might be another way to do what i want to do... But I thought there would be some syntax for this. But i cant find it

#

nevermind I figured it out. I will have a block that is overridden on the pages I want the content to be different

rustic pebble
#

@native tide nope, even on desktop wrappers like electron or react you cant do it, because it is running a chromium browser on the background. Even on discord you can view the css

#

๐Ÿ˜‰

native tide
#

0 need to be a dick

rustic pebble
#

??

native tide
#

Hrmm ??

rustic pebble
#

Did I do something wrong?

#

@native tide I am sorry but I have no knowledge over django

native tide
#

No worries, I figured it out. In Django (and also in Jinja, which it is based on) you have blocks of content that you have on a base page. And you can over ride them on more specific pages. So for example, if you want something to only appear on certain pages, you have the content block be empty on the base template. Then you over ride in the child template. Its weird, but its accomplished the same thing as "if this url is the active url: load this"

#

Does Flask have a templating engine?

#

I know nothing about Flask.

rustic pebble
#

Flask uses Jinja

#

as well

native tide
#

ah. They call it DTE in Django and I dont know why. I think they started with Jinja and modified it over time and called the fork DTE

#

Its basically the same

#

as far as i can tell

rustic pebble
#

Well not sure, but I dont really use the engines I parse everything using js

native tide
#

right, right. I learned to use the templates because of static page generators like pelican.

#

I like their effect, although I admit the syntax makes html look a little ehhhh

#

But its okay. It works

rustic pebble
#

I prefer my html to be cleam

native tide
#

Well, so do I. And I do my best.

rustic pebble
#

I use a seperate js file for each html file I have

#

say I have the following
file1.html
file2.html
file3.html

#

I will also have
file1.js
file2.js
file3.js

native tide
#

I definitely separate js from html unless I am just messing around and not sure I will use something yet. It would be nice if the templating engine was not so... directly a part of the HTML. But it is. Its effect is worth it looking weird. And I magine I will get used to it.

#

The same way I gotr used to every tag having a million bootstrap classes

rustic pebble
#

I am so bad at frontend anyways

native tide
#

I am okay with CSS. Not great. But I can do it.

#

Even without bootstrap

rustic pebble
#

So that is why I seperate it because I really despise
reading html

native tide
#

although it will not be great.

#

It will just work.

#

mm

rustic pebble
#

I am a backend developer my styling abilities are very narrow

#

But I am still way better than some frontend devs smh

#

Bootstrap is my savior tbh

native tide
#

You're not the only person haha. I have only made one design with CSS that was fully responsive that I was proud of. But it was simple. Its was just... elegant. But bootstrap saves the trouble of focusing on frontend if youre not great at it.

rustic pebble
#

well my latest website although it is barely legal in the context of this server

#

it has very good design

native tide
#

https://virufac.github.io/ -- that is my non bootstrap static page. I have not updated it since I made it. lol. but its nice for being done without help. I mean, I wouldnt use it to sell a product. But its pretty enough.

rustic pebble
#

Like it is very responsive and has many dynamic elements inside it

#

Gotcha

#

Adjusting the css took me way too much time compared to what it took me to create a very secure login/logout system

native tide
#

Yeah, that is the trouble with frontend. It's a lot of moving things back and forth and being like, "No that's not just right, no that's not just right."

#

And it takes forever.

rustic pebble
#

Yup

#

But tbh I have chosen a very poor backend architecture as well, I started the project when I was in a plane and I didnt rly think about it

native tide
#

But to be fair

rustic pebble
#

before I knew it in around 6 hours I had written a very solid base

#

And I was way too bored to change it

native tide
#

I would have no idea how to make a login secure without this framework I use

#

whereas I can make CSS if I have to.

#

ITs just tedious

rustic pebble
#

I am not using any of flask's auth framework

#

frameworks*

#

I always emphasize on security and I make sure I have the best and fastest modules. I usually use JWT infused cookies to create sessions and I hash passwords with a private key and in order for the user to login I just check the hash I never dehash it using a public key

#

So every password is stored hashed on my db, and the cookies the client has are also signed meaning that no one can access their contents without both of the keys I have

#

The ... you see at the end continue for around 150 chars

#

And this is a cookie containing info like client's username, first name, day joined, etc

#

But never passwords

native tide
#

Yeah that is the kind of thing that I Django does for me and I dont know how to do any of myself.

I could learn. I mean, I know how to create a hash. So I theoretically could do it.

But it would be an entire thing I had to learn first before I could do this if not for Django is what I mean.

#

And I admin that it does make me feel cheap, like Im skipping a lot of work that I should know how to do on my own.

#

But... I also have only been programming for a year so.

#

Ive come pretty far.

rustic pebble
#

I dont mean an admin pssword

#

I mean storing the passwords to the db

native tide
#

Yeah.

#

You should look at Django.

#

Its amazing lol

#

I will eventually check Flask out. Ive been told it has as use case where it might be better.

#

I cant comment really on things i dont know though

rustic pebble
#

That is a dashboard

#

u made?

native tide
#

No that is built into Django by default.

#

Its ridiculous how much that thing does.

rustic pebble
#

Ohh

#

I dont rly like that

#

It means you have less control over what you build

native tide
#

No, you can change it any way you want to.

rustic pebble
#

idk

native tide
#

Im not trying to sell you anything. You can literally do whatever you want to do.

rustic pebble
#

Yeah chill mate haha

#

I really want to look on electron as my next project wrapper

#

And have flask backend

native tide
#

Thats cool. I wouldnt make up your mind about Django though until youve seen it.

#

You can change everything about that admin page.

#

It just happens to come with a lot of tedious things done for you.

rustic pebble
#

I literally reinvent the wheel with every app I make so I donโ€™t find what django provides particularly fitting for my developer style

#

I am going on a trip tmrow

native tide
#

Right.

rustic pebble
#

Ill have a look at it while I am travelling

native tide
#

Its entire design philsophy is to never do that.

#

I will say that a lot of times building with it feels like

rustic pebble
#

Yea I got that haha

native tide
#

"Okay where is the thing in the documentation I need to write over to change this."

rustic pebble
#

Flaks is almost starting from zero

native tide
#

Instead of like

#

"Okay im going to write this function to do this."

rustic pebble
#

Yea I gotcha

native tide
#

Its constantly writing over a function that already exists

#

yeah

#

I will have to check Flask.

#

I can see the appeal of that

rustic pebble
#

Like djangoโ€™s literal slogan is โ€˜A framework for perfectionistsโ€™

#

Meaning it has everything set up for you

#

You just need to connect the parts

#

Whereas flask is almost entirely different

native tide
#

perfectionist with deadlines lol

tired root
#

I've got a headnut for your two

#

    {% for key, value in skills.items() %}
    <input class="accordion-checkbox" type="checkbox" id="{{key}}" />
    <label class="accordion-label background-silver" for="{{key}}">
        <r-grid>
            <r-cell class="left-1em text-bold">{{key}}</r-cell>
            <r-cell class="text-right text-bold">group SP</r-cell>
            <r-cell class="text-right text-bold">{{len(skills[key])}}</r-cell>
        </r-grid>
    </label>
    <div class="accordion-content">
        {% for skill in each %}
        <div class="accordion-item">
            <p class="left-1em">
                <strong>{{skill["name"]}}</strong>&nbsp;(Rank X)
                <span class="accordion-level-square">
                    {% set empty_squares = 5 - skill["trained_skill_level"] %}
                    {% for n in range(skill["trained_skill_level"]) %}
                        <i class="fas fa-square"></i>
                    {% endfor %}
                    {% for e in range(empty_squares) %}
                        <i class="far fa-square"></i>
                    {% endfor %}
                </span>
            </p>
        </div>
        {% endfor %}
    </div>
    {% endfor %}```
native tide
#

But yeah... You can still build on to it.

tired root
#

This is the jinja template

rustic pebble
#

yea smthing like that

native tide
#

Wow thats cool, are you working a web game too?

tired root
#

Everything that is under {% for skill in each %} ends in the html outside of accordion-content

rustic pebble
#

yes

tired root
#

but why?

rustic pebble
#

Hmm

#

And that is the part where I would force my way with js

#

Let me have a look

tired root
#

the for comes after the <div>

rustic pebble
#

I can see that

native tide
#

I have never used r-grid or r-cell, does it work like table, tr, and td?

#

oh its an input

tired root
#

it's a custom tag for grids

rustic pebble
#

this is how I make tables

var table = document.getElementById('responsetable');
for (var i = 1; i <= data['accnumber']; i++) {
    let tr = document.createElement('tr');
    let td1 = document.createElement('td');
    let td2 = document.createElement('td');
    let td3 = document.createElement('td');
    let text1 = document.createTextNode(data['account' + i]['server']);
    let text2 = document.createTextNode(data['account' + i]['username']);
    let text3 = document.createTextNode(data['account' + i]['password']);

    td1.appendChild(text1);
    td2.appendChild(text2);
    td3.appendChild(text3);
    tr.appendChild(td1);
    tr.appendChild(td2);
    tr.appendChild(td3);
    table.appendChild(tr);
#

hmm

tired root
#

tables are awful for layouts

#

anyway, I have a problem and I am not shooting js on it

native tide
#

Yeah. I havent used a table since I was in high school tbh.

#

What is the problem exactly?

rustic pebble
#

Have you tried switching the {% for key, value in skills.items() %} from the start to right before div class="accordion-content">

tired root
#

@native tide That the <div class="accordion-content"> comes after the for loop

#

and is empty

native tide
#

ohh ok

tired root
#

everything from the for loop is supposed to be inside that div

rustic pebble
#

Hmm

#
    <input class="accordion-checkbox" type="checkbox" id="{{key}}" />
    <label class="accordion-label background-silver" for="{{key}}">
        <r-grid>
            <r-cell class="left-1em text-bold">{{key}}</r-cell>
            <r-cell class="text-right text-bold">group SP</r-cell>
            <r-cell class="text-right text-bold">{{len(skills[key])}}</r-cell>
        </r-grid>
    </label>
    {% for key, value in skills.items() %}
    <div class="accordion-content">
        {% for skill in each %}
        <div class="accordion-item">
            <p class="left-1em">
                <strong>{{skill["name"]}}</strong>&nbsp;(Rank X)
                <span class="accordion-level-square">
                    {% set empty_squares = 5 - skill["trained_skill_level"] %}
                    {% for n in range(skill["trained_skill_level"]) %}
                        <i class="fas fa-square"></i>
                    {% endfor %}
                    {% for e in range(empty_squares) %}
                        <i class="far fa-square"></i>
                    {% endfor %}
                </span>
            </p>
        </div>
        {% endfor %}
    </div>
    {% endfor %}
#

This wouldnt work right?

tired root
#

no

rustic pebble
#

damn it

tired root
#

Its a dict of dicts and the values are needed on the top

rustic pebble
#

Sure

tired root
#

please no wild guessing around, I am looking for a real answer

rustic pebble
#

Yeah I don't think I can give you one, I am really not sure how jinja works, I always use js for that shit

native tide
#

So... the only thing that I have to say is that

#

in DTE you dont put () at the end of your methods in templates

#

Is that the same?

tired root
#

Also, @rustic pebble , the issue is the inner loop

#

which methods?

native tide
#

In whatever you are using

#

like...

#

You just omit () in templates in Django

#

Every one I have seen does that

rustic pebble
#

This one I pressume?

#
        {% for skill in each %}
        <div class="accordion-item">
            <p class="left-1em">
                <strong>{{skill["name"]}}</strong>&nbsp;(Rank X)
                <span class="accordion-level-square">
                    {% set empty_squares = 5 - skill["trained_skill_level"] %}
                    {% for n in range(skill["trained_skill_level"]) %}
                        <i class="fas fa-square"></i>
                    {% endfor %}
                    {% for e in range(empty_squares) %}
                        <i class="far fa-square"></i>
                    {% endfor %}
                </span>
            </p>
        </div>
        {% endfor %}
tired root
#

yes

#

and that content ends outside the div the loop is in

#

and that just boggles my mind

rustic pebble
#

Can you send a pic of how the content looks when it gets rendered?

tired root
rustic pebble
#

Damn frontend dude, we are 3 people here trying to solve something really easy I am sure

#

I am sorry, I don't know if it is something I am missing but I can't find anything wrong with what you have written. I hope I don't face the same problem sooner or later

#

Because that really makes you rethink the whole logic of that when it could be one tiny detail

native tide
#

I'm trying to find wherever I read that you're not supposed to put () on your method calls in a template syntax. But I cant find it.

tired root
#

what ()?

native tide
#

Im not sure if that would help you but its the only idea I have. You might try it

tired root
#

there are no functions here

native tide
#

skill.items()

#

remove the ()

tired root
#

no that is how it works in jinja

native tide
#

mm

tired root
#

also, if that wouldn't work, there would be no output

#

because it is the parent loop

#

console is for js

#

there is no js

native tide
#

Well, it was the only idea I had because Django has me omit them. Unless Im crazy. Good luck fixing it. I'll look out for the answer

rigid laurel
#

go back to just divs and ps, then colour the different levels with css

tired root
#

pycharm has pretty good jinja support and tells me when there are unclosed tags, even for parent templates.

#

but I try

rigid laurel
#

is it possible that you can just share the entire template via paste.pydis.com?

tired root
#

hold on

bleak bobcat
#

What's the problem ?

native tide
#

link above should take you back to it

bleak bobcat
#

Yea I clicked but all I see is html, no question

rigid laurel
#

Scorcher's next few messages explain

bleak bobcat
#

k

native tide
#

The screencap shows it.

#

I'm interested in the answer but I only just started using these templates.

bleak bobcat
#

So, to be sure I understand it, everrything is present in the generated html but is outside of the accordion-content div, right ?

tired root
#

I've solved that, not sure how, but I did. Apparently jinja does some weird things when there is an error in your for loop

#

but anyway, it is a dict of dicts

#

first loop: {% for key, value in skills.items() %}

#

so, value should be the second dict, right?

bleak bobcat
#

If it's a dict of dicts yea it should

#

what's each ?

tired root
#

for each in loop

bleak bobcat
#

for skill in each

#

what's each ?

tired root
#

the item from the other loop

#

value

bleak bobcat
#

wat

rigid laurel
#

in which case, it should be for skill in value

#

I assumed each was being injected into the template as well

#

like separately

tired root
#

okay, so if pretty print my loop variable, it shows this: ('name', 'Science')

#

and all the other keys

#

but when I do skill["name"] it's not showing up

bleak bobcat
tired root
#

same result

#

I am too stupid today to iterate a dict, idk

bleak bobcat
#

(also I still don't know what each is, I'm looking at jinja2's doc and I don't see it as a loop keyword, and if it was shouldn't it be loop.each ?)

#

At this point I'll take Charlie's suggestions for the whole template code ^^'

tired root
#

okay I am stupid

#

I had rewritten basically the whole project,used the old template, but didn't think

#

I only need one loop

rustic pebble
#

Sorry for interrupting, does anyone know how to change the input field's background color?

tired root
#
input[type=text]{
  background-color: red;
}```
rustic pebble
#

let me try this

#

thanks

tired root
#

@bleak bobcat @rigid laurel Thanks for trying to help though. Appreciate it

#

no js ๐Ÿ˜›

rustic pebble
#

Ooof

#

I would never be able to do that on jinja

tired root
#

css not jinja

rustic pebble
#

even worse for me haha

tired root
#

well, both

#

it has a hidden checkbox

bleak bobcat
#

cool

tired root
#

clicking the "label", that is where the arrow on the right is, changes it's children from display: none to block

#

Well the whole silver bar is the label

#

disadvantage: you cannot animate from none to block and vice-versa in css

#

with keyframes

#

it's missing some formatting, but the principle should be clear

native tide
#

Thank you.

rustic pebble
#

I feel like you are torturing yourself haha

tired root
#

Go into .accordion-checkbox and set the display to block

#

then the magic becomes clear

native tide
#

I am a fan of CSS checkboxes.

#

This is cool. I am planning a game that I am not as far along in as you. So I'll show you my stuff if i ever get around to having anything worth showing lol. Right now Im still drawing out my database and trying to make sure its perfect while I finish touching up this blog app. But this blog app is really only intended to teach me as many Django basics as possible. I ultimately want to make a web based RPG.

tired root
#

that is good

#

It is a small and light weight raster library

#

it's really awesome once you get the hang of it

#

And makes your site ready for mobile

native tide
#

I noticed it and wsa going to look at it later actually.

#

it was the first thing i noticed ha

#

I dont dislike bootstrap

#

But the web has become

tired root
#

There is where the <r-grid> tags come from

native tide
#

bootstrapified

#

I see.

tired root
#

didn't have to change anything

#

just works

rustic pebble
#

Can someone help me translate this into js?
/^[a-zA-Z ]+$/

native tide
#

Cool.

rustic pebble
#

Basically what I want is to check a field if the characters from the field are inside this /^[a-zA-Z ]+$/

#

Nvm I figured it

#

let regname = /^[a-zA-Z ]+$/; xd

native tide
#

Actually

#

That grid system looks really good for laying out RPG like stats and info.

#

And Im noticing that no matter how i zoom on that page

#

Nothing seems to change

#

Is that mobile friendly? Im not on a phone

tired root
#

yes

#

there are different modifiers

#

so, say you have 3 columns next to each other

#

<r-grid columns=3>

#

would have 3 columns in all size

#

<r-grid columns=3 columns-l=5 columns-s=1>

#

3 on medium, 5 on large and 1 on small screens

#

like phones

#

in portrait mode

native tide
#

right

#

This is almost like

tired root
native tide
#

They set out to make a grid system perfect for character sheets

tired root
#

can't delete the preview :/

native tide
#

Im definitely going to use this at least for that if not also with oth css

tired root
#

has 2 screens, one nomrla and one for phone

native tide
#

Cool

#

Yeah this is good

tired root
#

just need to make a button for the menu from the 2nd screen

#

so it can slide in

#

on the phone version

native tide
#

Here is my question at this point

#

How do you create your own HTML tags?

tired root
#
my-tag{
}```
native tide
#

Damn dude

#

You hit me with the perfect thing for what I am wanting to do haha

tired root
#

I'd use it sparingly though

#

the custom tags

native tide
#

Right right

#

I actually dont have any ideas worth doing with it.

#

I was just curious

rustic pebble
#

@tired root You making a game?

tired root
#

no

rustic pebble
#

oki :/

tired root
#

I am making a character planner for Eve Online, using their api endpoint to pull the data @rustic pebble

rustic pebble
#

Gotcha thanks for the info! I was thinking of doing the same for league of legends but I got too bored doing the frontend :/

dense slate
#

Has anyone implemented Paypal into a Django project? I have a basic buyer/seller setup, but I'm confused on how to implement a commission to the website as well as how to capture the successful transaction data that is sent back from Paypal. It is successful, but I'm not sure how to control/implement these two things on the server side.

rustic pebble
#

I have made it on flask

#

@dense slate

dense slate
#

Probably the same idea, sure.

rustic pebble
#

I can send you the code block of how it works, I cant explain rn tho

#

I am leaving soon

dense slate
#

Would love to take a look

rustic pebble
#

This has a lot that is unnecessary for you but its for you to tie things together

#

Take a look on createuserfromregister

#

This is the core function

#

โ€˜/atโ€™

#

Is to get the access token

#

/price is the function that fetched the frontend with the prices

#

So people cant edit the element out

#

@dense slate

#

Basically I have a register form, the user fills the inputs and then clicks on the paypal button

#

After he pays and if the payment was successful they get registered on my db

#

Let me send you the front end part as well

native tide
#

anyone know how i could level these boxes

#
* {
  box-sizing: border-box;
}

/* Float four columns side by side */
.column {
  float: left;
  width: 25%;
  padding: 0 10px;
  height: 300px;
}

/* Remove extra left and right margins, due to padding */

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Responsive columns */
@media screen and (max-width: 600px) {
  .column {
    width: 100%;
    display: block;
    margin-bottom: 20px;
  }
}

/* Style the counter cards */
.card {
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  padding: 16px;
  text-align: center;
  background-color: transparent;
}
#

css im using

rustic pebble
#

Frontend @dense slate

weary arrow
#

Potentially obvious question on flask/jinja2: How to import a block of code from another template, but not the whole template? Feel like I'm not doing this correctly:
I've a standalone sub_template.html that looks like:

{% extends "layout.html" %}
{% endif %}
{% block content %}
...
{% endblock content %}```

I only want the block content stuff included in another page, index.html:
```{% extends "layout.html" %}
{% block content %}
...
{% include 'sub_template.html' %}
{% endblock content %}```

But because index.html already extends layout.html, if I import the whole sub_template.html I'd be double extending layout.html - hence the if statement that checks current url in sub_template.html.

Any less ugly ways of doing this?
quasi ridge
#

my hunch is: you factor out the to-be-imported stuff into its own file, and import it in all places that need it

#

I think I've done this exactly once

#

it was surprisingly non-obvious ๐Ÿ˜

weary arrow
#

ah yeah, I tried doing that too but preferred the messy if statement over having an additional html file cluttering my templates folder. since jinja2 brags about reusability I figured there's a super obvious way of doing this

lavish prismBOT
#

Sorry, but you may only use this command within #bot-commands.

lilac root
#

How would one go about connecting multiple raspberry Pi's a django based website

restive kindle
#

simply; why

rustic pebble
#

@lilac root you can use docker => Kubernetes

lilac root
#

@restive kindle I'm trying to collect data from multiple raspberry Pi's and then display them on something like a dashboard

#

@rustic pebble is it possible for me to write a python script on the pi and make it send post requirests to the server

restive kindle
#

Like their temperature and stuff or collecting data from external source.

lilac root
#

@restive kindle GPS data

restive kindle
#

use database + websockets/post requests

lilac root
#

Yeah I've done that

#

Is there a way to make the pi's like an api

restive kindle
#

Like the server query the rpi-s individually?

lilac root
#

Yeah

#

Would that be better ?

restive kindle
#

It depends if they move around a lot / are they in distance of the server. Judging by the fact that you are collecting GPS data i'd probably have the rpis send data to the server.

rustic pebble
#

Yeah it is possible

#

But you would have to run the script on all the pis you have

#

Basically it will be something in the lines of:

import requests
import time

url=โ€œmyserverurlโ€
print(โ€œStats have startedโ€)

while True:
try:
   response =    requests.post(url=url,data=data)
except:
 continue
#

And data is your pi data

#

Which you can get from a module

#

@lilac root

#

If you want to make them an API then you have to create an internal server on one of the apis which you then make requests

#

It is not that hard to set up actually

#

Quite easy I must say

lilac root
#

So I would have a server to which all the pis would send the data to, and then use the main server to request the data

#

The thing is the rpis are just for testing, I was thinking of using Arduino for the property deployment

rustic pebble
#

You can do it however you want

#

Id rather have a network of pis connecting to a local server and then request to that local server rather than having each different pi

#

Makes it easier to manage and scaleable

lilac root
#

@rustic pebble so each pi will talk to a local server, then the main server would make requests to the local server ?, Sorry for reiterating, I just want to know if I got your idea

rustic pebble
#

Yup

#

Exactly that

#

Think of the local api server as a forwarding server

#

@lilac root

lilac root
#

Alright thanks a lot @rustic pebble

rustic pebble
#

Np

tranquil robin
#

In my django wepage I want to pass Json data to Javascript, which method is better (or if there is a better way):
1- add the Json data in the Django template, and read it in javascript by searching the DOM.
2- request the data using an Ajax request

restive kindle
#

The former saves requests and thereby load time if its dependent on the loading of the page. However I prefer the latter as it gives the backend lang and the frontend independence from eachother.

native tide
#

This was what I was talking about the other day when I said it seemed strange you had () in your code @tired root -- just so you know Im not crazy ๐Ÿ˜›

tired root
#

I believe you

native tide
#

๐Ÿ˜›

#

It disturbs me a little bit to think that DTE is that different from jinja. It looks so similar.

stark yarrow
#

Hey I'm building an app in Django and I have a question. I have a Abstract Model with common fields and methods. How do I access the child model in the parent class?

dense slate
#

@stark yarrow I'm not sure if this answers what you're asking, but you can do something like :
ParentClass(models.Model):

ChildClass(ParentsClass):

#

and that inherits all the parent fields.

native tide
#

If you are creating two models inheriting from the models.Models class and you want the second to be related from the first use ForeignKey, if you want to declare two models inherit from the models.Models class do what Damian mentioned.

stark yarrow
#

I've done this

#

Building a Reddit clone.
class Post and Comment inherit from Votable.
In the Votable methods I check for the type and do something based on the type

#

My only issue is with the class Vote.

class Vote(models.Model):
    UPVOTE = "UPVOTE"
    DOWNVOTE = "DOWNVOTE"
    UNVOTE = "UNVOTE"
    VOTE_STATUS_CHOICES = ((UPVOTE, "Upvoted"), (DOWNVOTE, "Downvoted"), (UNVOTE, "Unvoted"))
 
    user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name="Usuรกrio")
    status = models.CharField(max_length=10, choices=VOTE_STATUS_CHOICES, verbose_name="Estado")
    post = models.ForeignKey(Post, null=True, on_delete=models.CASCADE)
    comment = models.ForeignKey(Comment, null=True, on_delete=models.CASCADE)

I don't want to use ContentType, so I declared both fields and set them to nullable

#

Or should I use ContentType? I feel like it's too messy

#
 def get_vote_object(self, user: UserProfile):
        qs = Vote.objects
        if type(self) is Post:
            qs = qs.get(post=self, user=user)
        elif type(self) is Comment:
            qs = qs.get(comment=self, user=user)
        return qs

The problem with the way I'm doing this is that I have to type check everytime I use the Votable class.

polar nova
#

hello

#

how can i deploy python website to godaddy

#

it is like a grind

native tide
#

with git?

#

if you have ssh connect to the shared host/vps

rustic pebble
#

Yo

drowsy rune
#

@polar nova python on godaddy is probably not your best choice. I tried previously to no avail and since moved away from godaddy. I was using shared hosting so I'm pretty sure you have a lot more control in a vps.

#

hello @rustic pebble

polar nova
#

@drowsy rune which host do you use?

#

To get your custom domain

drowsy rune
#

I've used GCP for a couple of django sites.

polar nova
#

Can you get custom dom

drowsy rune
#

i believe it's relatively easy to deploy to digital ocean, pythonanywhere and heroku as well.

#

yeah, of course.

polar nova
#

Yes i think si

drowsy rune
#

you just have to pay for it ๐Ÿ™‚

polar nova
#

.)

#

:)

drowsy rune
#

what are you building?

polar nova
#

A web site for my electro mobile team

drowsy rune
#

nice. i'm not sure I know what that is. what framework did you use?

polar nova
#

Django

drowsy rune
#

Awesome.

polar nova
#

Yes

drowsy rune
#

is it ready for primetime?

polar nova
#

Yes

#

I will take a look at gcp

#

Thanks bra

drowsy rune
#

i've use a VPs (google compute engine) and the sAAs (app engine) and found the latter to be far easier to maintain.

toxic marten
#

I have a question. About frontend, i know js and jquery basics. But now, i want to choose one tecnology, and learn it well. I've done a quick search on google, it seems that most popular tecnologies are jquery, react and angular. Which one should i learn? Which one is the most used and demanded?

rustic pebble
#

It depends on what you want to do
jquery is very convenient for controlling dom elements, react is very good at creating sleek UIs, angular is kind of the both

#

I would suggest to also check out electron

rigid laurel
#

I'd suggest that React is the most useful of those

#

Its pretty nice for a JS framework (I much prefer it to jquery), its quite in demand in terms of jobs, and there's only one real version of it unlike Angular

toxic marten
#

PS: I suck with css, but I am comfortable with bootstrap. So, since I use bootstrap, my works are not custom, but always with the usual bootstrap components.

I forgot to tell you this

#

I say this because you say that react is used more for sleek UIs

rigid laurel
#

The sleekness of React UIs is less about them looking pretty - you're still relying on HTML/CSS for that - but about how easy it is to make things responsive

#

as in responding to data and input

native tide
#

I have a question about getting a gmail account setup to validate accounts and do password resets. I made a new email and tried to go set up an app password but I get

#

Does this have to do with the newness of the account or... have they discontinued this feature for common accounts?

#

I'm following a guide that says its as easy as setting this up.

#

ah, its a feature that only exists if you have 2FA on.

#

Which I definite would if I was in production. In fact, I'd feel kind of unpressional using a gmail account if I was, too.

#

But this is just testing

tired root
#

@native tide That feature was entirely scrapped

native tide
#

Ahh, okay.

#

I'll have to look at that but Ive been sort of stopped by another problem

#

I have a problem on my "staging server" that I dont have on my dev server.

#

Exception Value: Reverse for 'user-posts' not found. 'user-posts' is not a valid view function or pattern name.

it is though

blog/views.py

class UserPostListView(ListView):
    model = Post
    template_name = "blog/user_posts.html"
    context_object_name = "posts"
    paginate_by = 5

    def get_queryset(self):
        user = get_object_or_404(User, username=self.kwargs.get('username'))
        return Post.objects.filter(author=user).order_by('-date_posted')

blog/urls.py

urlpatterns = [
    path('', PostListView.as_view(), name='blog-home'),
    path('user/<str:username>/', UserPostListView.as_view(), name='user-posts'),
]

there's a template at blog/templates/blog/user_posts.html

I guess I'm going to try searching for every occurance of user-posts in all my files and see if something weird is somewhere but...
The crown wtf is working on one server and not the other.

#

Every route works that ive checked except for root. /

#

Which is weird because the home view has nothing to do with that class or that template

#

I am such an idiot

#

I've been on the test server so long I forgot I needed to restart gunicorn on the "staging server"

#

:shame:

#

okay, lets figure this OAuth thing out.

#

What do you use for mail validation ?

#

Not sure yet. Im learning to do it.

#

Oh

#

https://www.youtube.com/watch?v=-tyBEsHSv7w&list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p&index=12

This is the guide im following. This is password recovery though. I figured if I can get one set up the other shouldnt be too hard

In this Python Django Tutorial, we will be learning how we can use email to send a password reset link to a user so that the user can reset their password. Users will be able to fill out a form with their email and have a unique token sent to them, and if their token is verifi...

โ–ถ Play video
#

Oh sorry not a django guy i just know if u are going to use google smpt

#

Good luck either way

#

Yeah, I have to admit that turning that option on doesnt make me feel great or anything. Im pretty sure Id never do that in production. But im no where close to production anyway so..

#

In general u dont do that in production if u are going to handle some amount of mails like welcome mails pass reset and all that

#

u dont want it to end up in spam

#

right.

#

so sendgrind , mailchimp and so on come into the game

#

But is setting those up similar to setting up one in gmail? Because at this point I just want to know how to make it work.

#

Its fairly similar in flask you need few env varibales like mail_server = smtp.gmail.com the port, ur email , password

#

and using flask_mail is quiet easy like 5-6 lines function

#

Right that part will be easy. The part Im gonna have to learn is OAuth2

#

Alright dude keep it up sorry cant help u with that in django bet there is someone here that will answer so i wont spam hah

native tide
full nimbus
#
from selectorlib import Extractor
import requests 
import json 

# Create an Extractor by reading from the YAML file
e = Extractor.from_yaml_file('amazon.yml')

url = "https://www.amazon.com/RAVPower-Wireless-Charger-Adapter-Compatible/dp/B07SB41DQ3?smid=A2XR0GE58QDDNI&pf_rd_p=57e6c9a8-3db6-4b15-a07a-529e7121a3ab&pf_rd_r=8VD5S1G93G4RTHWJSJJC"
r = requests.get(url)

data = e.extract(r.text)
print(json.dumps(data, indent=True))

I'm trying to scrape the Amazon link for the price. I am not sure what I am doing wrong, this is my first attempt at web scraping. I'm using this .yml file:

Price:
    css: 'div.a-section div.a-section span.a-size-medium.a-color-price'
    type: Text

Output:

{
 "Price": null
}
native tide
#

I'm pretty sure that we're not allowed to help you because it against the Amazon terms of service. But... I will say that if you search a little bit, you will find the answers.

#

My advice is that if you really struggling to learn to scrape and you want to learn it in a manner that we are allowed to talk about

#

You choose a project where its not in any terms of service not to do it.

#

For instace, start with a scraping weather.gov or something like that.

#

Then we can help no problem. And you can take that where ever you want to.

haughty saffron
zealous siren
quasi ridge
#

darksky has a decent API too

full nimbus
#

@native tide I looked it up and it said that it is perfectly ok to scrape Amazon, and that it isn't against TOS

native tide
#
You may use Amazon Software solely for purposes of enabling you to use the Amazon Services as provided by Amazon, and as permitted by these Conditions of Use and any Service Terms. You may not incorporate any portion of the Amazon Software into other programs or compile any portion of it in combination with other programs, or otherwise copy (except to exercise rights granted in this section), modify, create derivative works of, distribute, assign any rights to, or license the Amazon Software in whole or in part.
#

I would take that to mean that you cant, but I am not an expert in these things. All I know is Ive seen people be told countless times in this community that we cant help with this subject. so...

#

I'm gonna err on not getting in trouble. But. If someone tells me I can tell you what to do, I will.

full nimbus
#

@native tide Tried it with weather.gov and it returned what I wanted, which was current temp

#

So I guess there is protection of some sort

#

It's just annoying however, as I want to have it check a price everyday. Oh well.

native tide
#

You just need to search man.

full nimbus
#

Yeah, I found a certain video

#

THat explains a certain thing I am trying to get

native tide
shy oasis
#

In regards to rendering templates with Flask, is there a way to render included JS files the same way?
Like if I was to write {{myvar.x}} in the js file is there a way for flask to substitute in the value?

Please ping me with any help.

hallow moat
#

@shy oasis you should just be able to do that in the same way as HTML - just call render_template() in your route function. Jinja2 (the template engine) works for any text document.

shy oasis
#

@hallow moat so it will work for the <script src=""sdsdsds.js"> tag?

hallow moat
#

Yes, but if you're including that file it'll need to be a route:

@app.route("/js/mydata.js")
def fill_data():
    return render_template("data.js", blah=blah)

In this case you might want to use an inline script tag instead, or pack the data into DOM elements.

shy oasis
#

Ah I see.

#

The inline script tag is what I detailed above right?

#

And when you say include do you mean with the include in js or the inline script tag? And if it is the inline script tag do I have to do the route

#

@hallow moat

hallow moat
#
<script type="javascript">
{{ your.data }}
</script>
shy oasis
#

Oh so just write the js in the html doc

hallow moat
#

Yeah.

#

Or, put your data in HTML tags / data attributes and then read those with your JavaScript, if appropriate.

shy oasis
#

data attribute?

native tide
#

Hi, how can I modified parameters using metaclass?
I wrote this and don't know how my class Meta can change params in init :

class Meta(type):
  def __new__(self, class_name, bases, attrs):
    a = {}
    for items in attrs.items():
      key, value = items
      if key.startswith('_') or key.startswith('__'):
        a[key] = value
      else:
        a[key] = value.upper()
    return type(class_name, bases, a)


class OnlyUpper(metaclass=Meta):
  x = 'test'
  y = 'second test'

  def __init__(self, name, surname):
    self.name = name
    self.surname = surname

o = OnlyUpper('my_name', 'my_surname')
print(o.x)
print(o.surname)```
quiet kite
#

Hi

#

Do you know if there's already an effort to make a TailwindCSS theme for Crispy Form ?

native tide
#

I'd probably go directly to people developing crispy forms with that one

#

So, I don't know if this will help you because I just started... or even if its the same thing

class UserUpdateForm(forms.ModelForm):
    email = forms.EmailField()

    class Meta:
        model = User
        fields = ['username', 'email']

But this is more akin to examples of the Meta class that I have seen. Maybe if you put that class directly into the other class you will have less trouble accessing its attributes?

Not sure. Maybe someone else knows.

arctic stag
#

Hi guys

#

I want to ask a question

#

I have a project where I need to implement an online store website. My team and I are unsure on which technology to use. We are all familiar with Python, so I suggested Django, but another team member says we should use ASP.net core. what are your opinions on what we should use.

rustic pebble
#

@arctic stag It really depends, ASP.net is based on C# which makes it easy to translate your website into a native application whereas Django is mostly website oriented. I would say you ought to go with django as it is more straight forward making you only have to deal with frontend, especially if you use PayPal's ready buttons to make transactions you can have a complete payment system in under 30 lines

#

Both are very good though so don't take my opinion for granted

#

You should really break down whether a WPF or a website isbetter for your needs

arctic stag
#

hmmmm

#

so we are expected to communicate with a database and show it on the website live/dynamicly

rustic pebble
#

That is Python territory, you can do that easily

#

I would suggest using flask/sqlalchemy

#

and jinja

arctic stag
#

so if a user would buy an item will i have the option to show the stock goinf down without refreshing the website?

rustic pebble
#

So you want live updates?

arctic stag
#

yeah

rustic pebble
#

There are 2 ways you can do that, either using javascript or backend using sockets

#

I would suggest doing this:
create a javascript function that works onclick, so when user buys the product the function makes a request to the server and the server replies with the new data

#

then the new data is passed to the stock graph

arctic stag
#

also why flask and not django

rustic pebble
#

for what you want to do it is way more straight forward

arctic stag
#

well I didnt go into full detail

#

but I will have different types of users as well, like customers, product managers, sales managers.

#

they will have different roles and features

rustic pebble
#

Well that is again quite easy

#

Using signed cookies

arctic stag
#

ok : D

rustic pebble
#

Take a look in JWT

#

You can add data into a jwt and then set it as a cookie

#

That way you can have different jinja renders based on role

arctic stag
#

oh cool

rustic pebble
#

You can also create decorators, like:

@customer
#

customer will be a function that is checks whether someone is a custom

#

if they are everything under it

#

will be for them

arctic stag
#

also how can i convince my team members to use django/flask rather than asp .net?
or how can i convince myself to use .net rather than django/flask?

rustic pebble
#

That is pure choice. But think of that: in flask you can have a server up and running with basic auth

#

in ~1 hour

#

whereas on asp.net you need more for sure

arctic stag
#

also this is for a software engineering course, so we do have limited time

#

and sprints every week

rustic pebble
#

I built a shop similar to your project in about 70 hours

#

on flask/sqlalchemy

#

I bet you can do it, especially if you have different roles

#

e.g.
1 frontend
1 backend
1 supervisor

arctic stag
#

yeah but we will also be shifting roles so that everyone can learn

rustic pebble
#

That wouldnt be too wise as you will have to comprehend each one's work each time

arctic stag
#

yeah but thats what the prof wants

rustic pebble
#

well again flask

#

is the easiest one

native tide
#

I don't know if I would take Kiwi at face value on whether you should use Flask vs Django lol. I think the general consensus though is that there is more to learn with Django. That being said, upon learning it, many things are already done for you. You can modularly pack them into projects and ship out.

#

I would research into it yourself tbh

#

I have a CSS question...

#

I know CSS pretty okay, but sometimes the more advanced stuff is over my head

#
*,
*::before,
*::after {
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
}

What is going on here

#

fun times

#

Basically, it loads that password update form with any random urlpattern entered after the expected one... without the tokens and stuff but the form is broken

#

If the tokens are right from the email, it will display the form correctly

#

So at least no one can change their password this way

#

But its kind of unprofessional to appear like this

#

Not only that but if someone manually enter the pages for password-reset-complete it will tell them that their password was changed when it wasnt.

#

I need to somehow... make those pages only viewable when directed to in the sequence of the password change progression

tired root
#

WEll, read the token from the url and if it does not exist, send the user elsewhere

#

@native tide

#
@bp_authentication.route("/auth")
@bp_authentication.route("/auth/<string:permission>")
def initiate_auth(permission=None):
    if permission:
        return redirect(eveAuth.get_login_url(permission))
    else:
        return redirect(eveAuth.get_login_url())
``` This is kind of the same. Different logic, but you get the gist
#

also redirect if it is wrong

native tide
#

The issue with adjusting all this stuff, which I will admit is the major issue with Django, is that I have to write some new class inheriting from another class to do it. And it is kind of more intimidating than just writing the thing yourself. Because whats going on behind the scenes is a lot to learn.

#

But I can do it.

tired root
#

In Flask it is a simple decorator with a function

#

I am using BLueprints though

#

makes this kind of thing a bit more modular

native tide
#

Its not going to be too hard probably. This is the url conf for the classes that you see which are in django.contrib.auth as auth_views. So I just have to find those classes and study them to see what I can add or change.

    path('password-reset/',
         auth_views.PasswordResetView.as_view(
             template_name='users/password_reset.html'),
         name='password_reset'),

    path('password-reset/done/',
         auth_views.PasswordResetDoneView.as_view(
             template_name='users/password_reset_done.html'
         ),
         name='password_reset_done'),

    path('password-reset-confirm/<uidb64>/<token>/',
         auth_views.PasswordResetConfirmView.as_view(
             template_name='users/password_reset_confirm.html'
         ),
         name='password_reset_confirm'),

    path('password-reset-complete/',
         auth_views.PasswordResetCompleteView.as_view(
             template_name='users/password_reset_complete.html'
         ),
         name='password_reset_complete'),
opal robin
#

hi, out of subject but is tkinter most used library for gui?

tired root
#

But I'd use QT or Kivy

native tide
#

I think its possible that I will eventually prefer Flask over Django. That being said, when I know Django well, I might not feel that way.

#

I'm not the sort of person to start one thing and start over again using another set of tools over and over again.

#

If I allowed myself to do that every time I saw a new thing, it would be bad.

rustic pebble
#

@native tide tbh for me Django is more team-oriented

native tide
#

Maybe. I don't really have enough experience in either to have a preference. I will eventually take a crash course doing a simple basic project in Flask like I just finished up with Django and see what is better for one or the other. Right now I don't want to have a bias because I just havent used both yet.

#

I definitely think from what i have seen that there probably is a use case where its better.

#

But i think the same is probably true for both depending on what you want to do and what you dont want to do.

#

What I can say about Django is that while it is impressively organized to do what it does, it's overwhelming and daunting the further away from the code that you get.

#

It starts to turn everything into a short cut

#

And the way it works is all under the hood.

#

I dont like that about it. Admittedly.

#

But once I understand it completely I imagine it will continue to impress me.

#

I'm starting to realize that the best way to learn Django once you get to where Im at in it...

#

Is opening up the actual code of the things you are importing and just reading the code.

#

Then reference docs as it does or deosnt make sense

little steppe
#

Is it possible to serve static files using Flask without using url_for in your template? For example, say I download some bootstrap theme/template that includes various static files like images/examplelogo.png or js/starterkit.js. If possible, I would like to update the routing rules in a single place, versus updating every single call in the template to use the url_for function. Any idea if this is possible? I can't seem to get anything working that does not use url_for(or manually adding a static/ prefix to the various calls)

rustic pebble
#

@little steppe Yes you can use /static/js/filename.js

little steppe
#

Ok, so I need to update all of the urls, there isn't some sort of routing rule I can add once? Just wondering. In the past I've updated the urls, but I was wondering if there was a much easier way haha

rustic pebble
#

I am not sure

little steppe
#

hmm ok, thank you for the link

rustic pebble
#

np

#

I am sorry I cant help but I usually write my own css,js, etc

#

So I dont have template problems haha

little steppe
#

Yeah I'm lazy and just trying to use a basic bootstrap landing page. In the past I have gone thru and updated every call with the static prefix. I figured it may be in my best interest to try to figure out how to get it working by updating 1 thing (routing rules) versus adding a prefix everywhere I need to

#

ha

rustic pebble
#

Well I cant help you there bud

native tide
#

Using templates is not "lazy"

#

Its sane.

#

That said

#

bootstrap is kinda lazy ๐Ÿ˜›

#

We have sort of reached a point in web dev where if you are creating something for marketing a product, you almost are forced to use some type of framework like that. Because people who are not webdevs see things that are really boot strappy

#

and they dont think what we think

#

They think, "Woooooww ooohhh cooool"

#

And you sort of have to.

rustic pebble
#

Well yeah

#

Bootstrap is the heaven for backend devs like me

little steppe
#

Realistically I would have been done by now if I just updated the various .css/.js/image urls throughout, I just figured now would be the time to see if there was a better way to do it. Its literally just a single page

native tide
#

Honestly, it taught me how to organize CSS better for scaling.

#

Even if I do it myself and customize it a lot

#

I would not be as organized without bootstrap showing me how to be

rustic pebble
#

Well the good thing is that most companies look for backend devs rn

#

So I dont really emphasize on front

native tide
#

So...

#

I may not be understanding your proble correctly stosho.

#

But is this something that you could solve with a global "find and replace all in files in these directories?"