How to setup django-fluent-comments on Django 1.6? - python

I am trying to use django-fluent-comments along with Django 1.6. I tried following their github README tutorial for setting it up but some features like threaded comments and AJAX are not working.
my settings.py has this
INSTALLED_APPS += (
'fluent_comments',
'crispy_forms',
'django.contrib.comments',
'threadedcomments',
)
COMMENTS_APP = 'fluent_comments'
urls.py has this
urlpatterns += patterns('',
url(r'^blog/comments/', include('fluent_comments.urls')),
)
my template post_details.html
<html>
{% load comments %}
<head>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}fluent_comments/css/ajaxcomments.css" />
</head>
<body>
<h1>{{post.title}}</h1>
<p>{{post.body}}</p>
<script type="text/javascript" src="{{ STATIC_URL }}fluent_comments/js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}fluent_comments/js/ajaxcomments.js"></script>
{% render_comment_list for object %}
{% render_comment_form for object %}
</body>
</html>
I am able to see some the comments that I post. But the features that are not working are
1) AJAX support, when I post a reply i get redirected to another page
2) Threaded comments, I simply do not see them.
How do I enable these features ?

Related

The HTML markup to include the image of Rango in the about template was not found

While creating a web app in Django, I've encountered a small issue. There seems to be a problem with my about template referencing. This is about.html:
<!DOCTYPE html>
{% load staticfiles %} <!-- New line -->
{% load static %}
<html> <head>
<title>Rango</title> </head>
<body>
<h1>Rango says...</h1>
<div>
here is the about page. <br />
<strong>This tutorial has been put together by Oliver Alan Stafurik</strong><br />
</div>
<div>
Index<br />
<img src="{% static 'images/rango.jpg' %}"alt="Picture of Rango" /> <!-- New line -->
<img src="{% static 'cat.jpg %'}" alt="Picture of a Cat" />
</div> </body>
</html>
Here's my settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
STATICFILES_DIRS = [STATIC_DIR,]
STATIC_URL = '/static/'
MEDIA_ROOT = [MEDIA_DIR, ]
MEDIA_URL = '/media/'
And here's my urls.py:
from django.contrib import admin
from django.urls import path
from django.urls import include
from django.conf import settings
from django.conf.urls.static import static
from rango import views
urlpatterns = [
path('', views.index, name='index'),
path('rango/', include('rango.urls')),
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I'm getting a traceback: File "/Users/stovifo/tango_with_django_project/tango_with_django_project/rango/tests_chapter4.py", line 254, in test_about_contains_rango self.assertTrue(required_str in self.about_response.content.decode(), f"{FAILURE_HEADER}The HTML markup to include the image of Rango in the about template was not found. It needs to match exactly what we are looking for. Check the book.{FAILURE_FOOTER}") AssertionError: False is not true :
EDIT:
The issue was just a small typo, where instead of "{% static 'cat.jpg'%}" I have typed in "{% static 'cat.jpg %'}".
try this you have just forgot to put 'cat.jpg' :
<!DOCTYPE html>
{% load staticfiles %} <!-- New line -->
{% load static %}
<html> <head>
<title>Rango</title> </head>
<body>
<h1>Rango says...</h1>
<div>
here is the about page. <br />
<strong>This tutorial has been put together by Oliver Alan Stafurik</strong><br />
</div>
<div>
Index<br />
<img src="{% static 'images/rango.jpg' %}"alt="Picture of Rango" />
<img src="{% static 'cat.jpg' %}" alt="Picture of a Cat" /> <!-- you make a mistake here -->
</div> </body>
</html>

CSS from static folder in Django [duplicate]

This question already has answers here:
Django CSS not updating
(11 answers)
Closed 2 years ago.
my first question here. I'm still new to both Django and CSS.
I'm trying to use CSS from Static folder in my Django project. It's all at a pretty basic stage.
In the 'static' subfolder 'css' I have one main.css file with example code:
body{
font-size: 20px;
background-color: black;
}
h1{
color: #008000;
}
In my settings.py file I have:
import os
(...)
DEBUG = True
(...)
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
And in my base.html template:
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shopping List</title>
<link rel="stylesheet" type="text/css" href="{% static '/css/main.css' %}">
</head>
<body>
<h1>TEST</h1>
{% block content %}
{% endblock %}
</body>
</html>
I've tried moving the css file, changing the view/url, and adding/deleting bootstrap (which alone works).
In the end my page just turns light blue-ish.
Thanks in advance.
So I checked your code and for me it works fine check if you have
'django.contrib.staticfiles' in your INSTALLED_APPS
If this didn't work I'm going to leave my code here, hope it helps.
-DjangoProject
-static
-css
-testing.css
template.html
{% load static %}
<link rel="stylesheet" href ="{% static 'css/testing.css' %}" type="text/css">
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',]
...
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
I just noticed that my STATICFILES_DIRS is a tuple and not a list like in your example, I don't think it makes any difference but you could try it.
Not sure if this will work, but try removing the "/" before css in your html file:
... href="{% static 'css/main.css' %}">

Django Static Precompiler not compiling files?

Django static precompiler does not seem to be working with scss files for me. I already checked if i had the compiler installed and my settings for django are are follows
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'static_precompiler',
'cms',
]
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'static_precompiler.finders.StaticPrecompilerFinder',
)
STATIC_URL = '/static/'
STATIC_ROOT = "static"
and i am calling the same from django template as follows
{% load compile_static %}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spacemailer</title>
{% block seo %}
{% endblock %}
<link rel="stylesheet" href="{% static 'style/main.scss' | compile %}" type="text/css" media="all" />
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
There are no errors whatsoever. The output is the same scss file with no compilations being made. Can someone point out what am i doing wrong with the same ? or some alternatives that will support compiling scss as well as coffee scripts
By default the compilation should be done at run time serving the template with
compilefilter.
{% static "js/alert.es6"|compile %}
Renders
<script type="application/javascript" src="/static/COMPILED/js/alert.js"></script>
If your using a different storage and STATIC_PRECOMPILER_DISABLE_AUTO_COMPILE is True compile using compilestatic before collectstatic
Verify the Compiler configuration
STATIC_PRECOMPILER_COMPILERS = (
('static_precompiler.compilers.SCSS', {
"executable": "/usr/bin/sass",
"sourcemap_enabled": True,
"compass_enabled": True,
"load_paths": ["/path"],
"precision": 8,
"output_style": "compressed",
}),
)

How should my Django file structure be set up?

I'm trying to set up my django file structure. I really don't understand this. It just isn't pointing to where I'd like it to go:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_PATH = os.path.realpath(BASE_DIR)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_PATH,'static/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_PATH,'media/')
I'm trying to build a file structure like this:
mysite
myapp
static
admin
css
js
img
media
tmp
templates
base.html
manage.py
So I'd like to get the settings.py to point to the right direction, I'm just at a loss doing so.
--------- edit ----------
It's not loading any of my content in those files, except for the templates
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}css/main.css">
<!-- Remove line below to disable test link -->
Back To Test Page
<title>My site - {% block title %}{% endblock %}</title>
{% block head %}
{% endblock %}
</head>
<body>
<style type="text/css">
body {background-color: #ADADAD; background-image:url('{{STATIC_URL}}img/r.jpg'); background-attachment:fixed;}
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
</style>
<div id="content">
{% block content %}
{% endblock %}
</div>
<div id="footer">
{% block footer %}
© Copyright 2014 by Me.
{% endblock %}
</div>
</body>
</html>
The picture doesn't get loaded
You can set your project structure according to this sample project Link.and you can also use Unipath for set you dynamic path in your setting.py file. you can run this project with collect static or without collect static.

Correct path/url for media files in django

I am using django 1.5.2 and I am having a hard time understanding the purpose of the media directory vs. the static directory and how to include stylesheets in my django project.
This is my directory structure:
django_books
beer
__init__.py
admin.py
models.py
views.py
random_book
(same as beer above)
django_books (the actual django project; beer and random_book above are my apps)
templates
base.html
beersall.html
__init__.py
settings.py
urls.py
views.py
wsgi.py
static
css
beers.css
media
css
beers.css
static
css
beers.css
manage.py
My beersall.html template (the beer output is correct, so just linking the stylesheet is wrong):
{% extends 'base.html' %}
{% block content %}
<div id="beer_list">
{% for beer in beers %}
{{ beer }},
{% endfor %}
</div>
{% endblock %}
My base.html file:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/media/css/beers.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/beers.css" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/beers.css" />
<link rel="stylesheet" type="text/css" href="/static/css/beers.css" />
<link rel="stylesheet" type="text/css" href="/Users/username/Projects/django_books/media/beers.css" />
<link rel="stylesheet" type="text/css" href="/Users/username/Projects/django_books/static/beers.css" />
<link rel="stylesheet" type="text/css" href="/Users/username/Projects/django_books/django_books/static/beers.css" />
{% block extrahead %}{% endblock %}
</head>
<body>
<div id="page_container">
{% block content %}
{% endblock %}
</div>
</body>
</html>
My settings.py file:
MEDIA_ROOT = '/Users/username/Projects/django_books/media/'
MEDIA_URL = '/Users/username/Projects/django_books/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
I should note that I am using the django development server, not apache.
The error in my browser (developer console) says beers.css is 404.
The url is localhost:8000/beers/ and my urls.py file correctly points to this and the views.py correctly serves the beersall.html template. How can I properly link my media?
EDIT
When I change the css link href value to /Users/username/Projects/django_books/media/ it still doesn't work.
EDIT 2
I've updated the href values to show things I've tried. Still not working...
User-uploaded files (by admins or site users) go to media directory.
Static files are files provided by developers (or from third-party apps).
Set something like this:
# Local disk paths
MEDIA_ROOT = '/Users/username/Projects/django_books/media/'
STATIC_ROOT = '/Users/username/Projects/django_books/static/'
# URLs visible in the browser's address bar
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
And in Your template use the STATIC_URL variable:
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/beers.css" />
And move your styles to the django_books/static/ directory.
in my project:django_learn, in template: check_uncheck_all.html, part pf the code:
{% load staticfiles %}
<html>
<head>
<script type=text/javascript src="{% static 'js/jquery-1.9.1.js' %}"></script>
</head>
you can also have a look at my settings.py
The static files were being found, but the permissions were not set up correctly. (i.e. a 403 not a 404 server error)
<VirtualHost *:80>
WSGIScriptAlias / /Users/username/Projects/django_books/django_books/django.wsgi
#the directory tag before was /Users/username/Projects/django_books/django_books/>
#this was one directory too deep
#from my structure above, you can see I needed to change my directory tag to this:
<Directory /Users/username/Projects/django_books/>
Order Allow,Deny
Allow from All
</Directory>
<Directory /Users/username/.virtualenvs/django_books/lib/python2.7/site-packages/django/contrib/admin/static/admin/>
Order Allow,Deny
Allow from All
</Directory>
Alias /static/admin/ /Users/username/.virtualenvs/django_books/lib/python2.7/site-packages/d$
Alias /static/ /Users/username/Projects/django_books/static/
</VirtualHost>

Categories