I'm trying to figure out the best way to display products inside my homepage. I'm building my website using the sandbox that already comes with django-oscar (I cloned the project from Github).
I discovered that the default homepage is controlled by 'promotions' app. However, my products are just being displayed inside 'http://localhost:8000/catalogue' (controlled by 'catalogue' app).
Is there a way to display the products in my homepage? Or will I have to change the default app that controls the homepage? (in this case, how can I do that?)
EDIT 1: I believe that I found a solution. You can follow the tutorial How to Customize an Existing View; however, you need to make some changes, so your code must looks like this:
from oscar.apps.catalogue.views import CatalogueView
class HomeView(CatalogueView):
template_name = 'promotions/home.html'
This way you will have access to the products in your 'promotions/home.html'. I'm not sure if it is the best way to implement this, if someone else has an alternative to this solution, please comment.
For this purpose Oscar has an app called promotions
. This application is responsible for rendering blocks of content on the homepage, among other things (as I can see you found out from the documentation).
Usually you would use the promotion app to add products and other types of content to a page. This can be done from the Dashboard, using Content blocks
, which can be found under the Content
menu.
There are a few types of promotions that you can define (single product, automatic, and hand picked product list, and others).
After defining your promotion, you will be able to associate it with a page route, which in your case should be /
.
If you choose to change this behaviour, then the documentation should provide a good starting point.
I also wanted to watching catalogue as a default page and I had find solution through nginx rewrite func at the end of /etc/nginx/sites-available/myproject
This file looks like this:
server {
server_name yourdomainorip.com;
access_log off;
location /static/ {
alias /opt/myenv/static/;
}
location /media/ {
alias /opt/myenv/media/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
rewrite ^(/)$ http://yourdomainorip.com/catalogue/$2 permanent;
}
来源:https://stackoverflow.com/questions/30013814/adding-products-in-django-oscar-homepage