These are chat archives for django/django

22nd
Dec 2017
Surya Poojary
@staymetal
Dec 22 2017 08:34
Hi guys I'm new to Django!
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:28
welcome @staymetal !
Im stuck on a website im making. I am trying to upload images via the django admin it doesnt work. Can u please tell me what i am doing wrong???

templates
{% extends "layout.html" %}

{% block title %}Projects{% endblock %}

{% block content %}
    <div class="text-center mt-5">
        <h1>My projects</h1>
    </div>

    {% for project in projects %}
    <div class="card" style="width: 20rem;">
        <img class="card-img-top" src="{{ project.image.url }}">
  <div class="card-body">
    <h4 class="card-title">{{ project.name }}</h4>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
      <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>
{% endfor %}
{% endblock %}
models:
from django.db import models


class Project(models.Model):
    name = models.CharField(max_length=255)
    language = models.CharField(max_length=255)
    description = models.TextField()
    image = models.ImageField(default="default.png", blank=True)
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:34
Settings for media:
STATIC_URL = '/static/'

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
please @ me if you can answer
shahraiz ali
@shahraizali
Dec 22 2017 09:40
anybody know any open source project with django backend and react/angular front end i want to understand the crud using these technologies
@Hasan-Ahmad whats your project structure make sure static folder is in right place
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:42
I dont have static folder, only using bootstrap
Im new to django btw
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:48
how do i show my project structure?
shahraiz ali
@shahraizali
Dec 22 2017 09:49
project structure means what is your files and folders hierarchy. your settings show that you should have a static folder in root folder which is supposed to have your css/js and static files likewise media files
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:49
i dont have a static folder becuase im only using bootstraps cdn
I only have a media directory
should i make a static directory and put the media directory in static?
shahraiz ali
@shahraizali
Dec 22 2017 09:55
you can but thats not necessary have a look at this
also what does the error say ?
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 09:58
it isnt an error, its just that my image wont load on the template
i followed the model part of the link u sent me but the image still wont load
shahraiz ali
@shahraizali
Dec 22 2017 10:01
oh then there is nothing wrong with uploading the image.
next check for urls if media urls are added

urlpatterns = patterns('',

# ... the rest of your URLconf goes here ...

) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

something like this
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:03
i will try it
which urls are you talking about? The project wide urls or app specific?
shahraiz ali
@shahraizali
Dec 22 2017 10:06
project
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:06
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

from . import views


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name="home"),
    path('blog/', include("blog.urls", namespace="blog")),
    path('projects/', include("projects.urls", namespace="projects")),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_URL)
this is the project wide urls
shahraiz ali
@shahraizali
Dec 22 2017 10:08
yup looks fine
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:09
but the image isnt loading
onto the template
shahraiz ali
@shahraizali
Dec 22 2017 10:09
is image present in media folder
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:10
yes
shahraiz ali
@shahraizali
Dec 22 2017 10:14
inspect to see if anything is present in src
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:15
it is present in src but just wont show image
shahraiz ali
@shahraizali
Dec 22 2017 10:16
copy whats in src and paste it after localhost:8000/ in address bar see what error it gives
it could be just permissions what operating system are you using
?
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:17
Page not found 404
:]
@elcolie
Dec 22 2017 10:18
Hi
I am setting up a gitlab-ci.
Stuck with problem
Soorena
@iamsoorena
Dec 22 2017 10:24
@elcolie check comments
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:26
I FIXED IT @shahraizali !
shahraiz ali
@shahraizali
Dec 22 2017 10:27
great what was it ?
:]
@elcolie
Dec 22 2017 10:27
@iamsoorena One moment
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:27
you see in my urls, i put MEDIA_URLS twice. I was meant to put settings.MEDIA_ROOT
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

from . import views


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home, name="home"),
    path('blog/', include("blog.urls", namespace="blog")),
    path('projects/', include("projects.urls", namespace="projects")),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
in the urlpatterns +=
shahraiz ali
@shahraizali
Dec 22 2017 10:28
damn
Hasan-Ahmad
@Hasan-Ahmad
Dec 22 2017 10:28
Thanks for the help ali!
I appreciate it a lot that u took some time to help me
shahraiz ali
@shahraizali
Dec 22 2017 10:31
np. ☺️
Luke-VideoLibre
@LukeVideo
Dec 22 2017 10:57
@shahraizali go for https://www.youtube.com/watch?v=S8wayjpaUJM It may be a bit out of date but it explains pretty wells how to use React with django.
shahraiz ali
@shahraizali
Dec 22 2017 10:58
sure thanks.
Luke-VideoLibre
@LukeVideo
Dec 22 2017 10:58
The most important i guess is getting webpack configured with your django app.
shahraiz ali
@shahraizali
Dec 22 2017 11:02
yeah btw whats your opinion on django with react vs angular?
Luke-VideoLibre
@LukeVideo
Dec 22 2017 11:04
I never used angular i couldn't say.
Surya Poojary
@staymetal
Dec 22 2017 11:13
Hi guys
How do I configure Django with MySQL
mounikeshmintu
@mounikeshmintu
Dec 22 2017 11:33
hey guys can anyone suggest me best ways to integrate django with angularjs
anykind of reference links or blogs
mohammadreza
@ultra2mh
Dec 22 2017 15:03
guys
django and angular4 have thier own url manager
how can use angular url pattern
in my django app
mounikeshmintu
@mounikeshmintu
Dec 22 2017 15:06
yeah i have the same doubt
shahraiz ali
@shahraizali
Dec 22 2017 15:08
its angular.js we are talking about
mounikeshmintu
@mounikeshmintu
Dec 22 2017 15:08
yes !!!
angular js
Soorena
@iamsoorena
Dec 22 2017 15:10
@mounikeshmintu and @ultra2mh read this
shahraiz ali
@shahraizali
Dec 22 2017 15:10
in that case mostly django is used for making a reat api and angular is used to get data and place where we want
Soorena
@iamsoorena
Dec 22 2017 15:11
it's one possible way for using these together. there is no right way. @ultra2mh @mounikeshmintu
and also consider using drf
mohammadreza
@ultra2mh
Dec 22 2017 15:12
im using angular 4|5 ... is that link usefull for me
what is drf
Soorena
@iamsoorena
Dec 22 2017 15:13
and also @ultra2mh read this
shahraiz ali
@shahraizali
Dec 22 2017 15:13
not so much
mohammadreza
@ultra2mh
Dec 22 2017 15:13
ok soorena thankyou
shahraiz ali
@shahraizali
Dec 22 2017 15:13
drf (django rest framework)
Soorena
@iamsoorena
Dec 22 2017 15:14
@ultra2mh that link will give you the idea. unless you want to use a boilerplate that's fine.
mohammadreza
@ultra2mh
Dec 22 2017 17:29
guys i read the related posts... i almost did not understand anything
:|
can anyone explain it to me more clear and smoother
plz
@shahraizali @iamsoorena @mounikeshmintu