How to construct home page URL to render DetaiView with Django?












0















Please, help me to write correct URL to render context on the home page.
Thanks to the kind help received here, I have the following code:



model:



import datetime
from datetime import datetime, timedelta
from django.utils.translation import ugettext as _
from django.db import models

class DayOfWeekSchedule(models.Model):
“""Dynamic days of week"""
def days_of_week(self):
days = {
'1': _('Monday’),
'2': _('Tuesday’),
'3': _('Wednesday'),
'4': _('Thursday’),
'5': _('Friday'),
'6': _('Saturday'),
'7': _('Sunday')}
DOW_CHOICES =
today = datetime.today()
for i in range(7):
day_number = (today + timedelta(days=i)).isoweekday()
day = days[str(day_number)]
DOW_CHOICES.append(day_number, day)
context = dict(DOW_CHOICES)
return context


view:



import datetime
from datetime import *
from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import DayOfWeekSchedule

class DayOfWeekSchedules(DetailView):
model = DayOfWeekSchedule
template_name = 'schedule.html'
def get_context_data(self, **kwargs):
context = super(DayOfWeekSchedules, self).get_context_data(**kwargs)
context_a = self.object.my_dict()
return render(request, self.template_name, context)


url:



path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’),


and I get on http://127.0.0.1:8000/ the Error 404. I would like to see my page on 127.0.0.1:8000, not on 127.0.0.1:8000/1/.



I also highly appreciate the relevant reading recommendations.










share|improve this question




















  • 2





    Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

    – Alasdair
    Nov 22 '18 at 11:37











  • set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

    – Vikas Gautam
    Nov 22 '18 at 11:40













  • explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

    – Vikas Gautam
    Nov 22 '18 at 11:50











  • No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

    – kokserek
    Nov 22 '18 at 15:50


















0















Please, help me to write correct URL to render context on the home page.
Thanks to the kind help received here, I have the following code:



model:



import datetime
from datetime import datetime, timedelta
from django.utils.translation import ugettext as _
from django.db import models

class DayOfWeekSchedule(models.Model):
“""Dynamic days of week"""
def days_of_week(self):
days = {
'1': _('Monday’),
'2': _('Tuesday’),
'3': _('Wednesday'),
'4': _('Thursday’),
'5': _('Friday'),
'6': _('Saturday'),
'7': _('Sunday')}
DOW_CHOICES =
today = datetime.today()
for i in range(7):
day_number = (today + timedelta(days=i)).isoweekday()
day = days[str(day_number)]
DOW_CHOICES.append(day_number, day)
context = dict(DOW_CHOICES)
return context


view:



import datetime
from datetime import *
from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import DayOfWeekSchedule

class DayOfWeekSchedules(DetailView):
model = DayOfWeekSchedule
template_name = 'schedule.html'
def get_context_data(self, **kwargs):
context = super(DayOfWeekSchedules, self).get_context_data(**kwargs)
context_a = self.object.my_dict()
return render(request, self.template_name, context)


url:



path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’),


and I get on http://127.0.0.1:8000/ the Error 404. I would like to see my page on 127.0.0.1:8000, not on 127.0.0.1:8000/1/.



I also highly appreciate the relevant reading recommendations.










share|improve this question




















  • 2





    Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

    – Alasdair
    Nov 22 '18 at 11:37











  • set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

    – Vikas Gautam
    Nov 22 '18 at 11:40













  • explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

    – Vikas Gautam
    Nov 22 '18 at 11:50











  • No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

    – kokserek
    Nov 22 '18 at 15:50
















0












0








0








Please, help me to write correct URL to render context on the home page.
Thanks to the kind help received here, I have the following code:



model:



import datetime
from datetime import datetime, timedelta
from django.utils.translation import ugettext as _
from django.db import models

class DayOfWeekSchedule(models.Model):
“""Dynamic days of week"""
def days_of_week(self):
days = {
'1': _('Monday’),
'2': _('Tuesday’),
'3': _('Wednesday'),
'4': _('Thursday’),
'5': _('Friday'),
'6': _('Saturday'),
'7': _('Sunday')}
DOW_CHOICES =
today = datetime.today()
for i in range(7):
day_number = (today + timedelta(days=i)).isoweekday()
day = days[str(day_number)]
DOW_CHOICES.append(day_number, day)
context = dict(DOW_CHOICES)
return context


view:



import datetime
from datetime import *
from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import DayOfWeekSchedule

class DayOfWeekSchedules(DetailView):
model = DayOfWeekSchedule
template_name = 'schedule.html'
def get_context_data(self, **kwargs):
context = super(DayOfWeekSchedules, self).get_context_data(**kwargs)
context_a = self.object.my_dict()
return render(request, self.template_name, context)


url:



path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’),


and I get on http://127.0.0.1:8000/ the Error 404. I would like to see my page on 127.0.0.1:8000, not on 127.0.0.1:8000/1/.



I also highly appreciate the relevant reading recommendations.










share|improve this question
















Please, help me to write correct URL to render context on the home page.
Thanks to the kind help received here, I have the following code:



model:



import datetime
from datetime import datetime, timedelta
from django.utils.translation import ugettext as _
from django.db import models

class DayOfWeekSchedule(models.Model):
“""Dynamic days of week"""
def days_of_week(self):
days = {
'1': _('Monday’),
'2': _('Tuesday’),
'3': _('Wednesday'),
'4': _('Thursday’),
'5': _('Friday'),
'6': _('Saturday'),
'7': _('Sunday')}
DOW_CHOICES =
today = datetime.today()
for i in range(7):
day_number = (today + timedelta(days=i)).isoweekday()
day = days[str(day_number)]
DOW_CHOICES.append(day_number, day)
context = dict(DOW_CHOICES)
return context


view:



import datetime
from datetime import *
from django.shortcuts import render
from django.views.generic.detail import DetailView
from .models import DayOfWeekSchedule

class DayOfWeekSchedules(DetailView):
model = DayOfWeekSchedule
template_name = 'schedule.html'
def get_context_data(self, **kwargs):
context = super(DayOfWeekSchedules, self).get_context_data(**kwargs)
context_a = self.object.my_dict()
return render(request, self.template_name, context)


url:



path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’),


and I get on http://127.0.0.1:8000/ the Error 404. I would like to see my page on 127.0.0.1:8000, not on 127.0.0.1:8000/1/.



I also highly appreciate the relevant reading recommendations.







python django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 13:37







kokserek

















asked Nov 22 '18 at 11:19









kokserekkokserek

156




156








  • 2





    Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

    – Alasdair
    Nov 22 '18 at 11:37











  • set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

    – Vikas Gautam
    Nov 22 '18 at 11:40













  • explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

    – Vikas Gautam
    Nov 22 '18 at 11:50











  • No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

    – kokserek
    Nov 22 '18 at 15:50
















  • 2





    Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

    – Alasdair
    Nov 22 '18 at 11:37











  • set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

    – Vikas Gautam
    Nov 22 '18 at 11:40













  • explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

    – Vikas Gautam
    Nov 22 '18 at 11:50











  • No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

    – kokserek
    Nov 22 '18 at 15:50










2




2





Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

– Alasdair
Nov 22 '18 at 11:37





Are you sure you want to use DetailView? A detail view is for showing the detail about one object. If you remove the pk from the URL, Django cannot automatically tell which object to display the detail for. Which object do you want to display the detail about on the homepage? Please show your schedule.html.

– Alasdair
Nov 22 '18 at 11:37













set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

– Vikas Gautam
Nov 22 '18 at 11:40







set your url path('', DayOfWeekSchedules.as_view(), name='schedule’)

– Vikas Gautam
Nov 22 '18 at 11:40















explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

– Vikas Gautam
Nov 22 '18 at 11:50





explaining @Alasdair answer, DetailView means you want to show details about an object so you must need pk or any unique field to represent that object and must pass to your url, like you did path('<int:pk>/', DayOfWeekSchedules.as_view(), name='schedule’), but if you want your home page like path('', DayOfWeekSchedules.as_view(), name='schedule’) this means you are showing list of all objects in your home page and should use ListView instead of DetailView.

– Vikas Gautam
Nov 22 '18 at 11:50













No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

– kokserek
Nov 22 '18 at 15:50







No, I am not sure that I need DetailView. I just wrote on a fragment of the whole task, which I have problem with right now. I have no experience, and I am looking for my way by trying different solutions. If you can recommend me a better way to move ahead, I highly appreciate it. Here is a fragment of my template. ‘c’ is a key of context dictionary. … {% for c in context %} <table class="table"> <tr> <td> Today {{ ‘c’ }} </td> </tr> … </table> …{% endfor %}

– kokserek
Nov 22 '18 at 15:50














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429807%2fhow-to-construct-home-page-url-to-render-detaiview-with-django%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429807%2fhow-to-construct-home-page-url-to-render-detaiview-with-django%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin