Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,726 members, 7,809,774 topics. Date: Friday, 26 April 2024 at 02:39 PM |
Nairaland Forum / Science/Technology / Programming / Let's Build A Simple Blog With Python(django) (7056 Views)
Nairaland Should Switch To Python/django. Opinion / Learn How To Create Websites With Python(Django Web Framework) / MY JOURNEY WITH PYTHON!!! (2) (3) (4)
Re: Let's Build A Simple Blog With Python(django) by Welete(m): 11:52am On Oct 10, 2017 |
following |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 8:06pm On Oct 11, 2017 |
open the website folder and edit settings.py file type blog in to this variable called installed apps INSTALLED_APPS = [ -----------'django.contrib.admin', -----------'django.contrib.auth', -----------'django.contrib.contenttypes', -----------'django.contrib.sessions', -----------'django.contrib.messages', -----------'django.contrib.staticfiles', -----------'django.contrib.humanize', -----------'blog', ] |
Re: Let's Build A Simple Blog With Python(django) by bilard(m): 2:34am On Oct 17, 2017 |
Carry on.. I am eagerly following you |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 12:27pm On Oct 17, 2017 |
inside the model.py file write the following command from django.conf import settings class Post(models.Model): -------ad_owner = models.ForeignKey(settings.AUTH_USER_MODEL,blank=True,null=True) -------title = models.CharField(max_length=200,blank=True,null=True) -------post = models.TextField() -------def __str__(self): -----------return self.post then go into your command line and type > python manage.py makemigrations > python manage.py migrate |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 12:28pm On Oct 17, 2017 |
bilard: this is my email johnsonoye34@gmail.com |
Re: Let's Build A Simple Blog With Python(django) by 4kings: 11:14pm On Nov 18, 2017 |
olamil34:Complete the tutorial na. |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 7:21am On Nov 19, 2017 |
i was banned brothers but now am back. |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 7:32am On Nov 19, 2017 |
Now go into views.py and create your first view with this code from .models import Post from django.shortcuts import render,redirect def index(request): ---- posts = Post.objects.all().order('-dateadded') # Order by the latest one created ---- return render(request,'blog/index.html',{'posts':post}) then create a file called urls.py and write the following code to it. from . import views # Imports all the view created by you in the views.py file from django.conf.urls import url urlpatterns = [ ----- url(r'^$', views.index, name='index'), # the first arguement is a regex pattern which django uses to route your links, the function imported tells django were to look for it, name is going to be used in your template to route from one page to another. ] |
Re: Let's Build A Simple Blog With Python(django) by 4kings: 7:59am On Nov 19, 2017 |
olamil34:Okay... Great to be back. Cc: greatface |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 8:52am On Nov 19, 2017 |
inside the website folder website | |---- settings.py |---- urls.py |---- wsgi.py go to the urls.py file and add the following code from django.conf.urls import url,include urlpatterns = [ ----------- url(r'^',include('blog.urls',namespace='blog')), ] The empty url means that it should load the page first without any title(www.example.com instead of www.example.com/blog) , include means that it should go to the blog > urls.py file and include it in the routing process, the namespace means ...... |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 2:06pm On Nov 19, 2017 |
4kings:Good to have you back olamil34 Thanks 4kings for reaching out to me. 1 Like |
Re: Let's Build A Simple Blog With Python(django) by 4kings: 6:44pm On Nov 19, 2017 |
Hmm, i can see another comment deleted up there. Looks like olamil34 has been banned again. If it's spambot send a mail to the supermod. |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 11:01pm On Nov 19, 2017 |
Please guys I need some help as soon as possible. I am trying to reference to models using ForeignKey. I have three models; user, topic and comment as examples. User model will have username field and other related fields. Topic will have user, title, detail, comment, comment_maker and maybe other fields. While, Comment model will have user, comment and some other fields. Can I use models.ForeignKey to link user, comment_maker of Topic model to User model and comment field of Topic model to Comment model? i.e can I use models.ForeignKey more than once in one model? Ex Topic Model: class Topic(models.Model): user = models.ForeignKey(User, ...) comment = models.ForeignKey(Comment, ...) comment_maker = models.ForeignKey(User, ...) I don't understand how OneToMany and ManyToMany fields work yet. cc: olamil34, 4kings, 2nioshine, TheCabal and others please help. |
Re: Let's Build A Simple Blog With Python(django) by 4kings: 12:42am On Nov 20, 2017 |
greatface: See: https://stackoverflow.com/questions/543377/how-can-i-have-two-foreign-keys-to-the-same-model-in-django https://docs.djangoproject.com/en/1.11/topics/db/examples/many_to_many/ |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 12:33am On Nov 21, 2017 |
4kings:Thanks For This. Thanks for always being there when you're needed. 1 Like |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 4:48pm On Nov 21, 2017 |
4kings: No you should not do dat please don't do that. |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 4:53pm On Nov 21, 2017 |
greatface: first this is a correction to the following model class Topic(models.Model): ---user = models.ForeignKey(User, ...) ---title = models.CharField(max_length=200) ---content = models.TextField() ---dateadded = models.DateTimeField(auto_now_add=True,blank=True,null=True) ---def __str__(self): ------return self.title class Comment(models.Model): ---user = models.ForeignKey(User, ...) ---topic_rel = models.ForeignKey(Topic) ---content = models.TextField() ---dateadded = models.DateTimeField(auto_now_add=True,blank=True,null=True) ---def __str__(self): ------return self.content |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 5:04pm On Nov 21, 2017 |
greatface: onetoonne(One user can have many comments and topics) manytomany(#hashtags can have many posts, many post can have many hashtag) |
Re: Let's Build A Simple Blog With Python(django) by 4kings: 5:07pm On Nov 21, 2017 |
olamil34:Please explain the concept. user = models.ForeignKey(User, ...) Thanks. |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 6:35pm On Nov 21, 2017 |
olamil34:I was able to get it working using "related_name" of ForeignKey argument as was mentioned in stackoverflow link posted by 4kings. Am yet to test this code but I must say the design logic looks better and more promising. Will makemigrations command not show errors at those two ForeignKeys? If it should work, could it be because the ForeignKeys references different models? |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 6:43pm On Nov 21, 2017 |
olamil34:Am seeing this rather late. Please why do you advice against such? |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 7:44pm On Nov 24, 2017 |
greatface: it will might work, but it will be very painful for to make changes because misstep could the the end the entire database |
Re: Let's Build A Simple Blog With Python(django) by greatface(m): 10:25pm On Nov 24, 2017 |
olamil34:Yea, you're correct. The migration passed but adding to any of the fields was almost impossible because the models inter reference each other through foreignkey which I never permitted null values. I later redesigned the models and am good now as I continue to learn. |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 9:00pm On Nov 29, 2017 |
sup peps, here is source code to the first version of quickfinda(python, django,), it's quite simple code. you can download it at github https://github.com/oyeolamilekan/quickfinda.git Enjoy |
Re: Let's Build A Simple Blog With Python(django) by kennyjam: 2:13am On Nov 30, 2017 |
olamil34:greetings bro. please i am very very new into coding,python to be precise. i dont know how to go about it. i have been going through the manuals and other stuffs but i am yet to make a head or tail of it. i first installed version 3.7 but later revert back into 2.7 thinking the later version will be more comprehensible, but to no avail still. i did download a video recommended on the python page for beginners but that video looks shallow. please i need ur suggestions, recommendations and advice on how to get started and how it will be easier for me. thanks, i await your reply. |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 8:47am On Nov 30, 2017 |
kennyjam: i recommend you read http://www.ebook-dl.com/book/263 (python for kids) it's actually the first python book i used, and then python crash http://www.ebook-dl.com/book/1636, extremely powerful and simple book. with these books, you will be creating somthing amazing within 1-2weeks. |
Re: Let's Build A Simple Blog With Python(django) by kennyjam: 9:59pm On Nov 30, 2017 |
olamil34: that will be nice then, thanks bountifully, bro... i will get back to u. |
Re: Let's Build A Simple Blog With Python(django) by kennyjam: 10:34pm On Nov 30, 2017 |
olamil34: please beside the python software, any more thing(s) to install? should i make use of the 2.7 or 3.7 python version? |
Re: Let's Build A Simple Blog With Python(django) by Nobody: 10:53pm On Nov 30, 2017 |
continue biko
will follow soon
when I repair my system, will try it |
Re: Let's Build A Simple Blog With Python(django) by Nobody: 10:55pm On Nov 30, 2017 |
kennyjam: same here too!! |
Re: Let's Build A Simple Blog With Python(django) by olamil34(m): 12:03am On Dec 01, 2017 |
kennyjam: python 3.x will be better, cause the python community will stop improvement python 2.x |
A Little Tip For Notepad++ users Like Me. / Python Creatives: Where Were We? / NIIT Past Questions And Answers Available Now
(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. 76 |