These are chat archives for django/django

6th
Jan 2018
:]
@elcolie
Jan 06 2018 07:40
@fccampelo Could you show me the TimeFieldMixin?
Amritpal Singh
@amrit3701
Jan 06 2018 15:56
Hello everyone
I am deploying Django with gunicorn and Apache but I unable to serve static files. Here is my apache conf file.
<VirtualHost *:80>
    ServerName domain.com
    Alias /static/ /home/amrit/Sim/Sim_site/drawing_freecad/static/
    <Directory /home/amrit/Sim/Sim_site/drawing_freecad/static>
        Require all granted
    </Directory>
    ProxyPreserveHost On
    ProxyPass /static !
    ProxyPass        "/" "http://127.0.0.1:6678/"
    ProxyPassReverse "/" "http://127.0.0.1:6678/"
</VirtualHost>
This gives me 403 error (Forbidden
You don't have permission to access /static/ on this server.)
avocadosarelife
@avocadosarelife
Jan 06 2018 17:34
hi @amrit3701
did you run 'run collectstatic' on the server?
Paul A. Aranguren
@Paulguren
Jan 06 2018 20:52
Hey guys, I need help w/ showing images in the development server
for the life of me, I’ve tried every single combination
and I got it to work for a split second a few days ago, but I pushed to github and I overwrote everything, like a goober. So please, someone can spot my issue:
# models.py:
class catalogdb(models.Model):
    '''
    This is used to handle the actual themes for WP.
    '''
    name = models.CharField(null=False, max_length=20)
    dateAdded = models.DateField(auto_now_add=True)
    dloads = models.IntegerField(default=0)
    imgpocket = models.ImageField(null=False, upload_to='wpstore')
    filepocket = models.FileField(upload_to='themes')
    desc = models.TextField(null=False, max_length=500)
    categ = models.CharField(max_length=15, choices=CATE_CHOICES)
    new = models.CharField(max_length=7, choices=NEW_CHOICE)


    def __str__(self):
        return "{0}/\n{1}/\n{2}/\n{3}/\n{4}/\nNew:{5}/".format(
                                                            self.name,
                                                            self.dateAdded,
                                                            self.dloads,
                                                            self.desc,
                                                            self.categ,
                                                            self.new
                                                            )
# settings.py:
STATIC_URL = '/static/'
MEDIA_ROOT = '/Users/Paul/Desktop/data/python/django/wpdb1/cont/media'
MEDIA_URL = '/media/'
# html:
{% extends 'wpstore/index.html' %}

{% block content %}
<div class="container1">
<p>
  this is the catalog bro
</p>
{% load static %}
  {% for this in catalog %}
    {{ this.name }}
    <br />
    {{ this.imgpocket }}<br /><br /><br />
  {% endfor %}
  <a href="{{ catalogdb.filepocket.url }}"> download here</a>
  <br /><br />
  {{ catalog.imgpocket.url }}
  <img src"{{ catalog.imgpocket.url }}" />
  <img src"{{ catalog.imgpocket }}" />
  <img src"{{ catalogdb.imgpocket.url }}" />
  <img src"{{ catalogdb.imgpocket }}" />
  <img src"{{ MEDIA_URL }}{{ catalog.imgpocket.url }}" />


</div>

{% endblock %}
and finally the views
# views.py:
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from datetime import time
import time
from wpstore.models import catalogdb


# Create your views here.
def index(request):
    return render(request, 'wpstore/index.html',)

def cataview(request):
    catalog = catalogdb.objects.all()
    return render(request, 'wpstore/catalog.html', {'catalog': catalog})
I just can’t get any image to show up on the dev server
Also, I have many img links linking images to see if there was a specific combination that could work.
Paul A. Aranguren
@Paulguren
Jan 06 2018 20:58
one more, the urls
# urls.py:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('wpstore.urls')),
]


if settings.DEBUG is True:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)