Can't get django-inplaceedit to work - django

The top of my HTML template contains:
{% load inplace_edit %}
Header part contains:
{% inplace_static %}
Then in my body contents I am doing:
{% inplace_edit "action.action_state" %}
But it's not working. I have installed:
'bootstrap3',
'inplaceeditform_bootstrap', # it is very important that this app is placed before inplaceeditform and inplaceeditform_extra_fields
'inplaceeditform',
'inplaceeditform_extra_fields',
'bootstrap3_datetime',
I have tried 'django.template.loaders.eggs.Loader', both enabled and disabled.
It shows up as a clickable text, but when I click/double-click nothing happens. How do I get it to work?
Thanks,
Hec

After trying #Goin's suggestion I found that my JQuery files were not being correctly imported. had to move:
<script type="text/javascript" charset="utf-8" src="{% static 'srt/js/jquery-1.10.2.min.js' %}"></script>
<script type="text/javascript" charset="utf-8" src="{% static 'srt/js/jquery-ui.min.js' %}"></script>
to the top of my header block. Anyone working with Bootstrap, please make sure you import JQuery as the first thing in your templates.
Thanks

Related

Django webpage only displays properly if a character is placed after {% load static %}

If I structure the first two lines of my HTML doc like this:
{% load static %}
<!DOCTYPE html>
It appears that none of the javascript or CSS run properly, and the webpage displays like this:
However, if I put any character after the {% load static %} expression,
For example, if I structure the first two lines of my HTML doc like this:
{% load static %}.
<!DOCTYPE html>
Then the scripts and CSS components run properly and the webpage displays as it should. Why is this?
Figured it out. For some reason, the content security policy that I had implemented was causing this issue. After removing the CSP, the static files began to behave in-line with expectations regardless of the presence/absence of a character after {% load static %}.
{% load static %}
<!DOCTYPE html>
You did it right but you have load the static files too like i did below.
<!-- js -->
<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
<!-- js -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/bootstrap-select.js' %}"></script>
You have to use this tag to load static files in template "{% static %}" this is the syntax for load static files.
#And give it the path in settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
And store css and js in static folder in your project too.Than its gonna work.
Make sure that the STATIC_URL of your settings is correct.

Django dropdown menu not working with tag 'load bootstrap3'

I am creating a website with django and I have a dropdown menu like this:
<li class="dropdown">
<a data-toggle="dropdown" href="#">{{ user.username }}</a>
<ul class="dropdown-menu dropdown-menu-left">
<li>Profile</li>
<li>Requests</li>
<li>Your cars</li>
<li>Your reservations</li>
</ul>
</li>
If I go to a page that contains this piece of code:
{% load bootstrap3 %}
{% bootstrap_javascript jquery='full' %}
The dropdown menu is not working, but if I remove the 2 lines above the dropdown menu works fine.
Knowing that I have to keep this 2 lines, how I am doing to solve this problem
you need to follow the sequence first bootstrap.css file second jquery.js then popper.js and then boostrap.js don't forgot to link popper.js this file are use for the open model
boostrap.css using link tag
jquery.js using script tag
popper.js using script tag
bootsrap.js using script tag
<head>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/popper.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</head>
i give CDN link put in your code other wise download those file and link them,i gave you the above stuff follow those sequence & don't forgot proper.js or jquery.js
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
if this work then make right answer if don't work please give the console error that show you in your browser,

Can't see Angular project inside Django

I am trying to run Angular inside Django project. I successfully installed it and have no errors when I run the Django server. However I do not see my Angular. app.component.html. I see my index.html of folder "templates" instead.
templates/index.html
{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<p>This is a mini-blog application using a back-end built on Django 2.0 and Django Rest Framework. It illustrates how to create and send JSON Web Token authentication headers with the HTTP requests.</p>
<app-root>Loading the app...</app-root>
<script type="text/javascript" src="{% static 'clientapp/runtime.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/polyfills.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/styles.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/vendor.js' %}"></script>
<script type="text/javascript" src="{% static 'clientapp/main.js' %}"></script>
{% endblock %}
Obviously, something is missing.
I am using this tutorial and looks like copied all the setttings:
https://www.metaltoad.com/blog/angular-api-calls-django-authentication-jwt
Thanks in advance.
In Django, Angular is nothing more than a set of static files.
So in order to make sure everything falls in its place, we need to load static files in order of their preference.
I suggest you visit index.html generated by webpack, just copy that order of javascript files in Django index.html in Django format.
For More info visit your browser console for errors.
For Ref: https://github.com/deepak1725/djangular
Sometimes the problem is absolutely silly as in my case.
I used old ng build.
Each time after change links to static files we need to run ng build

Django not finding some JS and CSS resources

Perhaps this is a laughable problem but am really lost. It was working fine until I ported the project to a new laptop. Here is my filesystem structure:
bill
==>bill (contains settings.py)
==>static
==>welcome
==>manage.py
Now in static i have my directory, i have folder plugins, js and css. The following are in my base.html template:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>{% block ownername %}{% endblock %} {% block title %}{% endblock %}</title>
<script src="{% static 'plugins/jQuery/jquery-2.2.3.min.js' %}"></script>
<!-- Bootstrap 3.3.6 -->
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'plugins/datepicker/datepicker3.css' %}">
**<link rel="stylesheet" href="{% static 'plugins/lobibox/lobibox.min.css' %}">**
<script src="{% static 'plugins/slimScroll/jquery.slimscroll.min.js' %}"></script>
**<script src="{% static 'plugins/moments/moment.min.js' %}"></script>**
It loads some resources while it gives 404 for some other resources that are there and working in my old laptop (the bold ones such as moment.min.js and css files). The configuration is the same since I used virtual environment to start it.
What am I missing please? I am really lost on what it is doing.
No question is laughable :)
To begin with, change {% load staticfiles %} to {% load static %}.
Then make sure you've got the correct settings in terms of static files. A good setup would look like this:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
If you are running your app without DEBUG=True, then also run python manage.py collectstatic --no-input from your terminal - that should do the trick to serve static assets in prod environment.
Try it and let us know how it went.

Having confusion with pathing in Django templates

When I use the url(r'^consultar/$', 'rcb.core.views.consultar'), in browser http://localhost:8000/consultar the consultar.html file find the jquery-1.11.2.min.js file, appearing the following information:
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/static/js/jquery-1.11.2.min.js
Request Method:GET
Status Code:200 OK
But when I use the url(r'^proposta/consultar/$', 'rcb.core.views.consultar'), in browser http://localhost:8000/proposta/consultar/ the consultar.html file not find the jquery-1.11.2.min file.js. Appearing the following error:
Remote Address:127.0.0.1:8000
Request URL:http://localhost:8000/proposta/static/js/jquery-1.11.2.min.js
Request Method:GET
Status Code:404 NOT FOUND
Could someone help me fix the code to run the url http://localhost:8000/proposta/consultar/
Below is the code and the structure of files and directories:
consultar.html
{% extends 'base.html' %}
....
base.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../static/js/jquery-1.11.2.min.js" type="text/javascript"></script>
</head>
<body>
{% block corpo %}{% endblock %}
</body>
</html>
views.py
def consultar(request):
propostas_salvas=search()
return render_to_response('consultar.html', { 'propostas_salvas' : propostas_salvas}, context_instance=RequestContext(request))
My structure of files and directories is:
rcb (Project)
core (is the App)
static
js
jquery-1.11.2.min.js
template
base.html
consultar.html
views.py
...
...
...
You should use path to javascript relative to your domain, not to document you're requesting, because for each document relative path to javascript would be different. So change that line:
<script src="../static/js/jquery-1.11.2.min.js" type="text/javascript"></script>
into:
<script src="/static/js/jquery-1.11.2.min.js" type="text/javascript"></script>
Or even better, load static in your template and use static file management built into django:
<script src="{% static "js/jquery-1.11.2.min.js" %}" type="text/javascript"></script>
That way you can change later your STATIC_URL in settings and django will correct path to your static files. Even if they are on different domain (some CDN or no-cookie domain just for your static files).