Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,731 members, 7,959,262 topics. Date: Thursday, 26 September 2024 at 01:10 PM |
Nairaland Forum / Science/Technology / Programming / Learn How To Create Websites With Python(Django Web Framework) (6184 Views)
Python With Django Web Development Training using Real World Projects! / Why Django Is The Best Web Framework For Your Project / Let's Build A Simple Blog With Python(django) (2) (3) (4)
(1) (2) (3) (4) (Reply) (Go Down)
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 2:49pm On Apr 01, 2020 |
damtan: Yeah. Just install pip to follow the tutorial. conda install pip |
Re: Learn How To Create Websites With Python(Django Web Framework) by damtan(m): 4:22pm On Apr 01, 2020 |
ColeDrain:How do I get that done please. It seems pip is preinstalled. Calling it out is the problems |
Re: Learn How To Create Websites With Python(Django Web Framework) by Daejoyoung: 4:58pm On Apr 01, 2020 |
damtan:Have you typed in pip install django on your command prompt? what was the result? if you don't get anything from that, then try: conda install -c anaconda django let's see if it works. 1 Like |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 10:06pm On Apr 01, 2020 |
pheww finally am doing well... boss Coledrain fire on.... you are doing well sir 1 Like
|
Re: Learn How To Create Websites With Python(Django Web Framework) by damtan(m): 10:10pm On Apr 01, 2020 |
Daejoyoung:I don't think django is preinstalled. Result says " no. matching distribution found for django |
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 10:34pm On Apr 01, 2020 |
damtan: Please post a screenshot of your anaconda prompt. |
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 11:38pm On Apr 01, 2020 |
POST 13 Things we've learned so far: views, urlpatterns, models, how the web works, admin site Moving back to the views We said views are functions that take request from the user(browser) and then generates a response which is sent to the user's browser. For now this is how our views.py looks like except you added any view to it for practice: from django.shortcuts import render Our polls website will have the following views: index view - displays latest questions to users detail view - displays details about a specific question results view - displays results for a particular question vote view - enable user to vote for a specific choice So basically, once a user comes to our website's home page, he sees latest questions, he can click on a specific question and vote for a choice and also see the total results. Update[b] polls/views.py[/b] as follows: from django.http import HttpResponse please convert the emoji to ) Let me explain some things So we said views are functions that take request from browser. but some of the views above take another argument question_id Okay, let's say the user sends a request to django that he wants question 2, how does django know the question the user wants to view?? Answer- through question_id(so that's why we have question_id) So user comes to our homepage sees 4 questions, he clicks on number 2, (request, 2) is sent to django, to help django know the user wants question 2 and then the detail view returns a response You're looking at question 2. Like we normally do, after creating our views we create urlpatterns, so go to polls/urls.py and update as such: (remove the once you created before, if you did) from django.urls import path Don't get worried, I will explain. So when a user makes a request he is basically sending a url to django. You type in nairaland.com/login, you are requesting for nairaland's login page. So in our polls website, once the user comes to our homepage 127.0.0.1:8000/polls django will check the mysite/url.py first and if you check your mysite.url/py which is this: from django.contrib import admin Django is looking for a urlpattern that matches 127.0.0.1:8000/polls/ once django sees that line[b] path('polls/', include('polls.urls'))[/b] it sees a match then it goes to the polls/urls.py and then matches path('', views.index, name='index'). You get?? Okay another example to clear things up. A user wants to see question 4, so he clicks it, this sends 127.0.0.1:8000/polls/4/ to Django, Django starts looking for a match. It first goes to mysite/urls.py and matches polls and then goes to polls/urls.py and matches path('<int:question_id>/', views.detail, name='detail') the <int:question_id>/ matches 4, then Django sends it to the view which then gives a response. Save the files, then run the server(py manage.py runsever) Go to your browser and try the following urls: 127.0.0.1:8000.polls/ 127.0.0.1:8000.polls/5/ 127.0.0.1:8000.polls/5/results/ 127.0.0.1:8000.polls/vote/ Always remember user sends a request, a url is sent to the Django, the url contains info about what the user wants, Django tries to find a match with the urlpatterns it already has, once a match is found the request is sent to the appropriate view(function) which returns a response to the user. 2 Likes |
Re: Learn How To Create Websites With Python(Django Web Framework) by Donoppy(m): 5:11pm On Apr 02, 2020 |
Nice work @coleDrain, I am currently halfway learning python programming on Udemy and just started reading your content for the first time and they really shed more light to the aspect of Django which am currently on. ColeDrain:.. Nice one bro ... Am following... God bless you . 1 Like |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 11:08am On Apr 04, 2020 |
ColeDrain: Something is not right,,,I keep getting syntax error...I copied and pasteed the codes in views.py and url.py..,I also changed the emoji to close bracket..j still don't y am seeing syntax error |
Re: Learn How To Create Websites With Python(Django Web Framework) by Daejoyoung: 11:44am On Apr 04, 2020 |
castrosteve:lndentation matters in python as well, so while copying and pasting codes, check your indentation. |
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 12:20pm On Apr 04, 2020 |
castrosteve: Help us to help you. Post screenshots of the error. |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 6:42pm On Apr 04, 2020 |
ColeDrain: ok
|
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 10:37pm On Apr 04, 2020 |
castrosteve: Check line 8 of your polls/views.py. Hope it's like this: def detail(request, question_id): If it is like that, then screenshot your views.py file. |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 9:20am On Apr 05, 2020 |
ColeDrain: its def function pass detail
|
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 10:23am On Apr 05, 2020 |
castrosteve: It should be this instead: def detail(request, question_id): |
Re: Learn How To Create Websites With Python(Django Web Framework) by MichelleObama: 1:47pm On Apr 05, 2020 |
I am having the same sintax error as well |
Re: Learn How To Create Websites With Python(Django Web Framework) by FredLum: 9:46pm On Apr 05, 2020 |
A suggestion, I implemented this: urlpatterns = [ path('', views.index, name='index'), path('<int:question_id>/', views.detail, name='detail'), path('<int:question_id>/results/', views.results, name='results'), path('<int:question_id>/vote/', views.vote, name='vote'), ] And the url was http://127.0.0.1:8000/2/results/ and http://127.0.0.1:8000/2/vote/ I modifed to this: path('<int:question_id>/', views.detail, name='detail'), path('results/<int:question_id>/', views.results, name='results'), path('vote/<int:question_id>/', views.vote, name='vote'), so the url http://127.0.0.1:8000/results/2/ or http://127.0.0.1:8000/vote/2/ worked, which I think is more preferable following OOP standards |
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 11:35pm On Apr 05, 2020 |
FredLum: Glad you are following to the point of even tweaking it to your preference. But: First, OOP has nothing to do with url patterns basically. Second, we first visit a question before we can then vote or check result that's why int:question_id comes first. Third, any of them is okay as far your URLs are intuitive to the user. Hope you get?? |
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 11:36pm On Apr 05, 2020 |
Sorry guys, I have been busy. Will continue tomorrow. Hope you are all doing well? |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 11:51pm On Apr 05, 2020 |
ColeDrain:ok it works but am getting 404 error but the url works with /admin
|
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 1:30am On Apr 06, 2020 |
castrosteve: Okay screenshot your polls/urls.py file and mysite/urls.py file. |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 9:58am On Apr 06, 2020 |
ColeDrain: ok
|
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 10:04am On Apr 06, 2020 |
mysite/url.py
|
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 12:34pm On Apr 06, 2020 |
castrosteve: Okay the problem is from your mysite/urls.py file. Change this line: path('', include('polls.urls')), to path('polls/', include('polls.urls')), And try again from ur browser. |
Re: Learn How To Create Websites With Python(Django Web Framework) by castrosteve: 1:34pm On Apr 06, 2020 |
ColeDrain: phew... am all good thankss... 1 Like |
Re: Learn How To Create Websites With Python(Django Web Framework) by FredLum: 3:20pm On Apr 06, 2020 |
ColeDrain: No p, meant URL pattern standard not OOP standard. When will you drop the next lecture? Regards 1 Like |
Re: Learn How To Create Websites With Python(Django Web Framework) by damtan(m): 6:34am On Apr 09, 2020 |
sorry bro. been off for a while. here is the screenshot ColeDrain:
|
Re: Learn How To Create Websites With Python(Django Web Framework) by Daejoyoung: 9:01am On Apr 09, 2020 |
damtan:Go to Anaconda prompt in your system, then type your codes there to see what gives. In Anaconda prompt, type....conda install pip. To get to Anaconda prompt, just type Anaconda prompt in the search area of your computer. OR just use conda only, start with: conda install -c anaconda django in your anaconda prompt not jupyter notebook. 1 Like |
Re: Learn How To Create Websites With Python(Django Web Framework) by damtan(m): 9:56am On Apr 09, 2020 |
Daejoyoung:I have done all these before this morning in the anaconda prompt and I have successfully created, activated and installed djangoenv in anaconda navigator. I have even seen the mysite folder and all other parameters that you stated created on my system. The problem is proceeding with the last command which is cd mysite py manage.py runserver An error message keeps popping
|
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:55pm On Apr 09, 2020 |
damtan: I don't really get your problem. But in your Anaconda prompt not jupyter notebook go to the directory that contains the manage.py file and type: py manage.py runserver Screenshot your anaconda prompt with the error there. |
Re: Learn How To Create Websites With Python(Django Web Framework) by damtan(m): 6:19pm On Apr 09, 2020 |
ColeDrain:Alright I'll do that soon |
Re: Learn How To Create Websites With Python(Django Web Framework) by KlausMichaelson: 8:51am On Aug 02, 2020 |
And that was how the story ended??
|
LAGOS Professional Training On Web Design&development With Certification.. / Help On Database Management System For A Hospital : Urgent / Is It That There Is Nothing To Code Anymore?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 84 |