Is this what you're talking about? For my site I just added templateViews as views. This puts the basic template at topmarq.com/about/ and uses the 'about.html' template. You can do the same with your home template.
So this method assumes that you don't have a dedicated view function for this HTML file. This only makes sense for pages where no context is needed. Eg 'static' pages. If your 'home' page isn't static you'll need to create a view function, and then call that function.
For a page that is not static, I call it this way:
urlpatterns = [
# Main Views
url(regex=r"^popular$", view=views.PopularThreadListView.as_view(),
name="thread_popular"),
And then in the App, I have a views.py that has a 'view' like this:
class PopularThreadListView(ListView):
"""A basic ListView """
model = Thread
paginate_by = 5
context_object_name = "threads"
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
return context
# Return the top most viewed recent Threads.
def get_queryset(self, **kwargs):
return Thread.objects.get_popular()
Any time you change the structure of your database you will need to 'makemigrations' (creates a file that tells the DB what to change and how) and then 'migrate' (actually tells the DB to update).
For instance, if you change your 'User' model to now include their birthday as a datetime field, you would need to go through this process to add a column in the user Table to store the birthdays.
Is this what you're talking about? For my site I just added templateViews as views. This puts the basic template at topmarq.com/about/ and uses the 'about.html' template. You can do the same with your home template.
Yes, how many different ways is there to doing that? It dosnt look like how several tutorials did it.
Hmm can you show the tutorial?
So this method assumes that you don't have a dedicated view function for this HTML file. This only makes sense for pages where no context is needed. Eg 'static' pages. If your 'home' page isn't static you'll need to create a view function, and then call that function.
For a page that is not static, I call it this way:
And then in the App, I have a views.py that has a 'view' like this:
class PopularThreadListView(ListView):
"""A basic ListView """
I’ve been watching “theNetNinja” Django tutorial. When do I make a migration?
Any time you change the structure of your database you will need to 'makemigrations' (creates a file that tells the DB what to change and how) and then 'migrate' (actually tells the DB to update).
For instance, if you change your 'User' model to now include their birthday as a datetime field, you would need to go through this process to add a column in the user Table to store the birthdays.
Ok, do I CD into anything or:
./venv/bin/activate
makemigrations
?
just be in the directory that contains your manage.py file.
Then run