#web-development
2 messages · Page 108 of 1
oh okay thanks i will check tht out
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
is there a channel for game makers?
Do you want to make a blackjack game??
no?
hey should we make a new virtual env for each django project ?
I would suggest a new venv for every new project
hey should we make a new virtual env for each django project ?
@winter spindle yes
I do not, why?
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
no
@winter spindle so you guys use anaconda ?
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?
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
why do you need a foreign key of the same table?
@static harbor Just make another model called reportrole, where some "X" is foreign key to the role table/model.
@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
Ok... I guess
Anyone know how to manage docker-swarm from github actions? Would like to integrate a cool "master push -> autodeploy"
@steel tiger https://github.com/marketplace/actions/docker-swarm-deploy ?
Only 15 stars
Doesn't seem to be any tutorials and i'd rather do something more tried and tested sort of thing
Cause swarm is on its last legs before death? 🙂
It is?
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.
Not using k8s because its overkill and cba learning the whole thing for a small cms
yeah I agree that k8s is often overkill
people try to use it even for the smallest of things which is silly
Swarm seems like the obvious small app with a couple containers sort of thing
yeah, then again, you can go pretty far for small projects with just compose
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
Ah
For nginx, should I have 1 per container?
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
I do. I had to tweak some security settings: https://hub.docker.com/repository/docker/thebouv/nginx-proxy
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
Ah, dope. One of the things I needed to do was host things at URLs that people can remember like say jenkins.thor.mydomain.com and harbor.thor.mydomain.com and solr.thor etc etc etc so I have a wildcard ssl on *thor.mydomain.com and each container I spin up I specify VIRTUAL_HOST=servicename.thor.mydomain.com and it all works and all through SSL. So handy. nginx-proxy is rewriting the config file dynamically to do that.
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.
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
you would add more servers to the upstream to load balance.
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?
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?
bruh why this chat so inactive
#bot-commands
how to make mobile app w/ python me lazy
@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
@native tide sure.
good afternoon, may I ask something here?
Sure
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
@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 blocks aren't right
@native tide ? how would i do this then?
Firstly, I don't think this is correct:
{% title = "{% block title %}{% endblock %}" %}
{% 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?
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
I don't understand what you're trying to say
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>
Yea, and I gave you the solution to that
{% block content %} <title>{{ title }} - GummyFN</title> {% endblock %}
yea but thats not really what i want
So, what do you want.
{% block title %}
{% if title !="" %}
<title>{{ title }} - GummyFN</title>
{% else %}
...
{% endif %}
{% endblock %}
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?
Yep... and there's your solution
wait does title become a variable when u set it as a block?
no. that's just a name
@wise lagoon try the code above
Read through the docs that would be your best bet
wait is it even possible to set a variable in a with statement to the value of a block?
can you elaborate
i mean can i set something that i input through a block to a variable?
@wise lagoon what do you mean by "input through a block"?
You pass a variable from your function to your block
not vice versa
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
I don't think you understand how Jinja templating works
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
what do you mean by "my function"
The function which handles the rendering of that page
what are you using flask or django
looks like flask
so... you're using flask?
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
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
read this part hopefully you will understand better
yes ik thats how i previously did it
So what's the issue here
aaand were back at the start
I've answered your question
not really
Then elaborate
can i just explain my question first?
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)
So how does this not fit your criteria?
{% block title %}
{% if title !="" %}
<title>{{ title }} - GummyFN</title>
{% else %}
...
{% endif %}
{% endblock %}```
lemme test it
it doesn't i think what he is trying to do is probably not possible
why?
or you could but bot like this
Bruh I gave you that like 20 mins ago and you didn't test it
how you want to solve it now
for your index.html you probably need something like this:```
{% extends "base.html" %}
{% set title = "string" %}
wait theres a set keyword
@wise lagoon you can do the same thing from your function
You pass a title to the template
i dont want to do it from my function tho
Then how you gonna do it then 😂
@wise lagoon How will the template know if the title is empty or not?
You have to pass a title to the template
otherwise you will have to use a workaround and use javascript
All this could've been avoided if you a) read the docs b) watched a tutorial
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
for your index.html you probably need something like this:```
{% extends "base.html" %}
{% set title = "string" %}
@polar trellis that kinda worked
What form.cleaned_data.get() is doing in django
@prisma jackal the docs explain that
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
Yes! thank you
np 🙂
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 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 🙂
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.
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?
@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?
@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
Ok, good thing you don’t have the GUI lol. You’ll need to recreate it with JS anyways.
You have the Django site all set up and ready to go? All you need to do is implement the games?
Well, this wouldn’t be a blog lol
I am guessing you will just start fresh then ?
I can change the blog to a portfolio or anything pretty easy its only bare basics
just been messing around
So are you wanting to serve to the user everything with JS then do all the logic in python?
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
Ok, well I’d suggest you probably start with the hangman as it will be easier IMHO.
you reckon? scrabble word is just literally input 1 rack
and it gives you all the possible words
thought that'd be easier
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.
Yeah, you will need to know it no matter what lol
Yea still trying to learn python really
so trying to not make that mistake of jumping to many different things
Ok
Why not just make the games using py game first?
Then later move into the web aspect of it
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
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.
I just thought it'd be fairly simple to implement a text based game on to django
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.
Yea that's why i wanted to try scrabble one first. It's pretty simple text based one atm
Well, if you don’t mind the refreshes then you can handle everything like a regular Django form.
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
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.
you thinking following something along these lines would be the way to go https://stackoverflow.com/questions/29977495/running-python-script-in-django-from-submit
the second answer from kossta seems to be something i could use
Yes, it’s like a regular Django form submission right(
yea that's what i was thinking of using as the input
Yeah, that would work.
alright I'll give it a crack thanks for the advice
Alright, cheers!
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
@sudden lynx follow the official django tutorial
i tried, but feels too hard for newbie in webdev
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
@brisk wadi routes are like proxies for your html
because you can name your routes anything
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
routes are only for view ¬ for all files
So? What can I do for my files?
are you using some framework?
Flask
I don't have much idea about flask because I use django
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
the css files are around 500 files, and many of the htmls had already been meta tagged to get to that specific folders
💯 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.
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
💯 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
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?
django
for serailzers?
@brisk wadi Not sure I follow. How does moving a file "ruin" HTML? hard coded paths?
for serailzers?
@stable kite wait
class Meta:
model = same
fields = '__all__'
class OnlySameSerializer(serializers.ModelSerializer):
class Meta:
model = same
fields = ['name', 'descriptions']```
I doubt anyone will help there tho, but I'll try
I'll help there. Will just be easier since others are using this channel also.
@tall plaza are you using django rest framework?
show your views?
queryset = Same.objects.all()
serializer_class = SameSerializer
class OnlyViewset(viewsets.ModelViewSet):
queryset = same.objects.all()
serializer_class = OnlySameSerializer```
i am getting output of only of OnlyViewset
yes
router.register('OnlySame/', views.OnlySameViewset),```
are you getting any error?
router.register('OnlySame/', views.OnlySameViewset),```
@tall plaza your views name is wrong here
if i dont use OnlySame url then it works fine
it should be views.OnlyViewset
but code you posted had wrong view
no i have correct
can you share your models?
name = models.CharField(max_length=200)
descriptions = models.CharField(max_length=300, null=True, blank=True)
profit = models.FloatField(default = 0)
no its ```same```` model
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
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
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
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
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
(following this tut: https://docs.djangoproject.com/en/3.1/intro/tutorial02/)
Having some problems with the django tutorial for windows
@long forge can you post your error
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
output
see also:
yeah i cant show the django admin :(
Oh my god you're kidding me
It was the settings.py
ok nevermind now I have a new error
@long forge this error is because of your timezone settings
have you created was_publishes_recently()
nah that's meant to be inbuilt
this is the first mention of it in the tutorial
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
@tall plaza check this out
https://stackoverflow.com/questions/21945796/how-can-i-use-two-different-model-serializers-with-the-same-model
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
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?
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?
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()
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
@haughty turtle you cant store images from user as STATIC it should be stored as MEDIA
where would that store it and how would I access it @stable kite
can you give an example
@haughty turtle https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-MEDIA_ROOT heres the docs link
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
@haughty turtle no its for the static which are css,js,img only
What is STATIC_ROOT? @stable kite
@haughty turtle used for using statics for production
iirc it's where everything goes when you run collectstatic as well
How would I get a selenium window to open in the background instead of popping up in the middle of my screen
@proper osprey you need to add the option to open headless
How would I do that?
Granted I have had some issues with it in the past when running headless.
Using chrome?
it's a pretty basic program, just clicks a couple buttons and then checks the html if a specific class exists
and yeah chrome
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.
alright, thanks
wait, it gave me an error
DeprecationWarning: use options instead of chrome_options
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
@proper osprey just change it to options lol
@shadow musk You just started it seems. What is the vision for this?
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?
use the requests module
or httpx
either would work as client based request systems
thx
@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.
CSS question here
Shoot.
@tardy briar There are probably a lot of people. Have you ran into some troubles we could help with?
How come my css does not work when I use flask
@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
<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
it should look like this, anyone?
mines look like this
anyone get any idea how I could do this or fix this?
anyone here?
@white spruce change the size of your image & add some margin between both
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
I want to get my container to show the button like this
but it;s showing like this
.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?
@white spruce increase the width of your button
dang, how did I miss that haha
thanks
@stable kite my newsletter is looking like this
trying to get like this
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
trying to get like this
anybody?
dang, everybody seems busy
@white spruce try display flex
I tried that @stable kite but I don't understand how I would get it to layout like that with flex
.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
anyone how do I get that button beside the inputfield
are you using a container for the input and button?
<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
try:
form{
display: flex;
}
when you set display = flex, by default flex-direction is row
so display: flex should be enough
what css code are you applying to style input and button?
.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;
}
I think I am getting close
.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;
}
did you change any html?
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
i have a problem with webbrowser module
its always good to post problems in codepen
my default browser is chrome yet it opens in ie
its easier to tweak code and help
I realize that, but not many people will come out of here to show stuff like that
can u just put a # b4 the channel where i can ask in this chat so that i can jump there \
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
you want to make its width bigger?
I guess its better to use a fixed width in this case
how can I get a space between the input and btn
yeah, got it on the input
also on the text
what if I want my text like this
instead of right across
well from your prototype
I think there is a container that wraps all your content right?
yh
so that container probably has a max width
I would set max-width in the wrapper container
and then the text would just wrap
idk man, check your prototype?
guess 600px?
actually did 100
.newsletter .container{
color: white;
justify-content: center;
max-width: 100px;
}
try 320px
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
@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>
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?
oh like an alert when you press the submit button ?
completely new to js
yeah
I heard about some innterText or innerHTML stuff
so I guess sumn like that
you can access by DOM
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>
@white spruce i think you referring to this https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick . But personally i like to use jquery for this sort of stuff as it can track event with on()
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
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
do you know about jquery ? @white spruce
something like this https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_click
yeah it's like a javascript library
I want someone to try writing this, so I can understand since I am new to js
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
what would that say when clicked
@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
haha I wasn't finished with that
I was just trying something
I am kinda trying sumn new
@white spruce if you just want javascript without learning jquery you can use this little hacky way
https://stackoverflow.com/questions/6157162/hook-into-an-onclick-event-without-using-the-html-property
/* 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
it brought you to the top of the page because your form was submitted and it reloaded the page
you need event.preventDefault()
I added that
oh nvm you already had that
I just want it to show anywhere that form submitted
@white spruce does your url included # after you click the submit button?
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>
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">
I remember no modifying html
so
I don't know what else to do lol
any idea
on how to fix something there
@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]
forms not form @white spruce
yeah
where you want the message to show up ?
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
under email input?
maybe alert box ?
@white spruce alert("I am an alert box!");
so remove
email.innerHTML
yeah since you don't want to touch html right?
i don't even know which DOM you pointing to with email though
yeah works now
was on
well that took some time
now got some small issues to fix
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
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
you should learn jquery too after you learned javascript, it's really useful and used alot
to do interactive webpage
without reloading page
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
I am trying to fix this
@white spruce w3schools is a really good site to learn for starter btw, it cover all the basics
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
oh i see
with css
but still got some minor stuff to fix
running out of time
I wanna get that inline
any idea
i have no idea because i don't know about your course
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
well i guess it's based on your time managing
I want my top like this
you should show your html and css codes
.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
do you use codepen ?
heard about it last week
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
want it to come out like this
can you edit my code pen?
or that doesn't work?
@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
so what about ```js
header h1{
font-size: 18px;
}
ul{
list-style: none;
float: right;
}
li{
float: left;
}
not needed
?
yeah it's still needed
look ok on my end
maybe because I got additional stuff
probably
add id to what?
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
you see it works right
but the whole other
half of the code
gets thrown out of it's place
kinda hard to pin point since i don't know your entire html css
@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
am I removing anything?
only .container one
i just added main before container and create the second container css block which point to header
header .container h1{
float: left;
}
header .container nav{
float: right;
}
and these new?
yes
still kinda messes up
it goes into the grey div
and at the bottom copyright gets messed up
yeah i see that because of your margin
it should be in the white
i didnt see the footer let me fix that
aite
@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>
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
some space like this
@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
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
i dont have the image so it doesnt show anything for me lol
@white spruce look ok for me
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
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
would I have to set them individually?
you can target it's class parent img
the parent class is learn-about
so @white spruce
.learn-about img {
height: 100px;
width: 100px;
}
and all my image would have been set the same?
gonna try to find a size that fits the card
@white spruce see, it only apply to those images in learn about
probably 300px width and height is the perfect size
you can modify the px until you find satisfied
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
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 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
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.
i've set that as default in my settings.py
'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
@ashen trench I think by default the user has permission to get & post data.
you manually need to change it
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
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
you can check if the user data has that permission to confirm it first
UserInstance.user_permissions.all()
@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.
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.
@ashen trench in default user model there an is_staff column to determind if user can access the admin
have you check if your user has is_staff = True or False ?
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.
@ashen trench try this
'rest_framework.permissions.DjangoModelPermissions', 'rest_framework.permissions.IsAuthenticated',
],```
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',
)
}
it should be a list
this is the configuration in settings.py
i know
are you sure ? what's the difference
@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
@native tide i am using class based views. And https://discordapp.com/channels/267624335836053506/366673702533988363/772749899120246785
in settings.py its set to default
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)```
you don't need to specify if it already listed in default auth of settings
but... you do
?
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
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?
@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
Yeah... But I'm talking about if you do list it in settings
then you use that authentication class instead of the default one
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
you can authentication_classes = () if you don't want any
isAuthenticated
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
@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',
)
}```
most of django functions accept both list and tuple
okay so if anyone has an answer for this https://discordapp.com/channels/267624335836053506/366673702533988363/772745666618327050
ping me
basically DjangoModelPermission is not working for me because of something i did wrong somewhere
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?
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)```
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).
Ideally something pretty minimal, like learn x in y minutes: https://learnxinyminutes.com/docs/python/
@mystic spindle https://www.youtube.com/watch?v=xv_bwpA_aEA&list=PL-51WBLyFTg2vW-_6XBoUpE7vpmoR3ztO and the whole series by him
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:...
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
@fleet bear check this out https://realpython.com/customize-django-admin-python/
Thanks, that should do the trick ;)
hi
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
@summer wyvern Ok, very simple, what seems to be the issue?
need help with setting up the website.
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
are you familiar with django templates
no
well you should start off with making a form
https://docs.djangoproject.com/en/3.1/topics/forms/
then have that form in a template. Once that's done you can access the inputted password in your django view and do whatever you need
I have been given that link so many times
is there a video?
that goes over the forms
thats up to you to find
ok
but that doc goes through every step
ok
so its a good resource
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
in general you would save the uploaded file somewhere and store the path to the uploaded file in the database
and then use mysql to query that path
@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:...
yes then you could use mysql to find the path to the file
yes or you could read through: https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask
@native tide Every time I run the server I get this error ```py
path('hello/', name),
NameError: name 'name' is not defined
name is the name of your view. Do you have a view?
good morning, I have a question
@summer wyvern ok, so can you explain what you think this code that you wrote means?
path('hello/', name)
if you go to http://127.0.0.1:8000/hello. it will redirect to the name.html file
I followed the tutorial and it worked fine
but that was with index.html
and I replaced it with name
and it doesnt work
path works like this: path(url, view)
and the view is the function which runs when you reach that url
?
you don't render html in the path variable
this is what is inside views.py
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})
is it necessary to have a 64bit system in order to use flask?
nice, thank you very much
as long as you got a cmd you can run flask lmao
I don't have cmd, I have terminal
same thing
nice
what is the name of my view?
get_name
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