Unable to access html page - django

Hello i dont know what the problem.. why when i click on button about us i am not able to be in the new page, but the url in the website change. The page reads only the extended block but the new one no.
this is the template (only the one related to the buttons)
<div class="btn-group cust-dropdown pull-right">
<button type="button" class="btn btn-default dropdown-toggle cust-dropdown" data-toggle="dropdown"role="button">
<i class="glyphicon glyphicon-menu-hamburger"></i>
</button>
<ul class="dropdown-menu" role="menu">
<li>About</li>
<li>Documentation</li>
<li>Pricing</li>
<li>Contact us</li>
<li>Register</li>
</ul>
</div>
This is the view:
def base(request):
return render(request, 'base.html', {'active_page':'base'})
def about(request):
return render(request, 'about.html', {'active_page':'about'})
And the about html:
{% extends 'base.html' %}
{% block title %}About{% endblock %}
{% block content %}
<div class='row'>
<div class="col-lg-6">
<h3>Summary</h3>
<p> Our organization is related to </p>
</div>
</div>
{% endblock %}
The image link is here, only the extendable form appear when i click on about

Related

Blog Post doesn't show images, bold text, or other attributes only the raw code... Django/Ckeditor

I've followed a tutorial on implementing a ckeditor RichTextUploadingField() to my blog so I can have more functionality and better looking post/blogs.
Everything seems to be working but when I go to see the actual post after adding the picture and some words. I get a raw output with all my text...
Here is my output on my blog
<p><span style="color:#1a1a1a"><span style="background-color:#ffffff">First of all, I have assumed that you have seen countless rubbish articles, and still can't understand classes and objects, but at least know that there are two things like classes and objects.</span></span></p>
<p><span style="color:#1a1a1a"><span style="background-color:#ffffff">Since you don't have programming experience, you can't understand Python's 'classes and objects' by analogy from the programming language you've learned. Let's use the example of life to build a house.</span></span></p>
<p> </p>
<p><span style="color:#1a1a1a"><span style="background-color:#ffffff"><img alt="" src="/media/upload/2019/11/08/01.png" style="height:268px; width:400px" /></span></span></p>
Not sure why it doesn't look like the output I get before I post the article while I'm editing and creating it.
MODELS.PY
from ckeditor_uploader.fields import RichTextUploadingField
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils import timezone
class Post(models.Model):
title = models.CharField(max_length=100)
# content = models.TextField()
content = RichTextUploadingField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return f'{self.title} --> {self.author}'
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})
POST_DETAIL.HTML
{% extends "portfolio_app/base.html" %}
{% block content %}
<div class="py-5 bg-light">
<div class="container">
<div class="row">
<div class="col-md-12">
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ object.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{% url 'user-posts' object.author.username %}">{{ object.author }}</a>
<small class="text-muted">{{ object.date_posted|date:'F d, Y' }}</small>
{% if object.author == user %}
<div>
<a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update Post</a>
<a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete Post</a>
</div>
{% endif %}
</div>
<h2 class="article-title">{{ object.title }}</h2>
<p class="article-content">{{ object.content }}</p>
</div>
</article>
</div>
</div>
</div>
</div>
{% endblock content %}
POST_FORM.HTML
{% extends "portfolio_app/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="container col-md-6">
<div class="content-section">
<div class="content-section">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom md-4">Blog Post</legend>
{{ form.media }}
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Post!</button>
</div>
</form>
</div>
</div>
</div>
{% endblock content %}
Am I missing something..? Thank you again for your help.
use |safe filter.
<h2 class="article-title">{{ object.title|safe }}</h2>
<p class="article-content">{{ object.content|safe }}</p>

How to convert Generic Views to Class based Views for lists with modals

I'm trying to convert generic views to class based views, so that I can get some better readability in my code.
From this I want to be able to create a function so that I can show modals for individual items in a list. I'm new to django so I don't know what I can try, I've searched online and read the docs but not having any luck.
View I'm currently using:
def my_booking_list(request):
booking_lab = Reservation.objects.filter(username=request.user.username).order_by('-id')
key = settings.STRIPE_PUBLISHABLE_KEY
print(booking_lab)
return render(request, 'my_booking_list.html', {'booking_labs': booking_lab, 'key': key})
Class based view I have no idea what I'm doing with (am I at least on the right track?):
class MyBookingsView(ListView):
def get(self,request ,pk):
booking_lab = Reservation.objects.filter(username=request.user.username).order_by('-id')
key = settings.STRIPE_PUBLISHABLE_KEY
print(booking_lab)
return render(request, 'my_booking_list.html', {'booking_labs': booking_lab, 'key': key})
Template (partial):
{% if booking_labs %}
{% for lab in booking_labs %}
<div class="tg-dashboardservices">
<div class="tg-dashboardservice">
<div class="tg-servicetitle">
<h2>{{lab.lab.name}}
{% if lab.status == 'Accepted' %}
<span>({{lab.status}})</span>
{% elif lab.status == 'Requested' %}
<span>({{lab.status}})</span>
{% elif lab.status == 'Denied' %}
<span>({{lab.status}})</span>
{% endif %}</h2>
</div>
<div class="tg-btntimeedit">
<span>{{lab.price}}</span>
<button class="tg-btnedite"><a data-toggle="modal"
data-target=".tg-categoryModal">
<i class="lnr lnr-pencil"></i></a>
</button>
<button class="tg-btndel"><a><i class="lnr lnr-trash"></i></a>
</button>
</div>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{%for lab in booking_labs%}
<!--************************************
Theme Modal Box Start
*************************************-->
<div class="modal fade tg-invoicemodal tg-categoryModal" tabindex="-1">
<div class="modal-dialog tg-modaldialog" role="document">
<div class="modal-content tg-modalcontent">
<div class="tg-modalhead">
<h2>Details</h2>
<ul class="tg-btnaction">
<li class="tg-delete"><i class="lnr lnr-trash"></i></li>
</ul>
</div>
<div class="tg-modalbody">
<ul class="tg-invoicedetail">
<li><span>Lab Booked:</span><span>{{lab.lab.name}}</span></li>
<li><span>Company Name:</span><span>{{lab.lab.company}}</span></li>
<li><span>Amount:</span><span>${{lab.lab.price}}.00</span></li>
<li><span>Payment Method:</span><span>Stripe</span></li>
<li><span>Booking Status:</span>
{% if lab.status == 'Accepted' %}
<span>{{lab.status}}</span>
{% elif lab.status == 'Requested' %}
<span>{{lab.status}}</span>
{% elif lab.status == 'Denied' %}
<span>{{lab.status}}</span>
{% endif %}
</li>
<li><span>Booking Dates:</span>
<span>From: {{lab.CheckInDate}} {{lab.CheckInTime}} </br>
To: {{lab.CheckOutDate}} {{lab.CheckOutTime}}</span>
</li>
<li><span>Name:</span><span>{{lab.lab.contact_person}}</span></li>
<li>
<span>Address:</span><span>{{lab.lab.street_address}}, {{lab.lab.city}}, {{lab.lab.country}}</span>
</li>
<li><span>Message:</span><span>{{lab.message}}</span></li>
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
<!--************************************
Theme Modal Box End
*************************************-->
{% endfor %}
{% endif %}
The code currently displays the modal 4 times, overlapping one another, I can click off of the modal to clear them, I know this is because of the for loop before the modal. I'm trying to achieve clicking on one item in a list to display its modal.
You can go through the django docs
In the list view just specify the model and paginate by count.
If you want to manually filter the queryset override the get_queryset() fun.
By default the context object name for the queryset will be object_list for a list view, So in the template loop over object_list. if you want to change it specify the context_object_name variable.

Py 3.6 // Django 2.1.4 : Accessing User Profile mysteriously changes the status of user.is_authenticated to True

I have been having this problem for 2 weeks now I can't seem to solve it.
I have a social website where user's can upload their resumes for recruiters to see.
And when I access some user's profile, the Navbar acts as if I am logged in, which I am not.
I tried fixing this issue by using get_queryset() ,it worked but I couldn't manage to display user's profile data.
so I stuck with get().
Here's a visual explanation:
As you can see the navbar says Home/Login/Signin
Now if I access John Doe's Profile, the navbar will switch to Home/Profile/Logout:
Here's my code;
views.py:
class HomeProfile(ListView):
"Di splays all active users in db"
template_name = 'profile/home_profile.html'
queryset = MyModel.objects.filter(is_active=True)
class Get_Profile(DetailView):
"fetches user's profile"
def get(self, request, pk):
user = MyModel.objects.get(pk=pk)
return render(request, 'profile/profile.html', {'user':user})
urls.py
urlpatterns = [
path('homepage/profiles/', user_view.HomeProfile.as_view(), name='homepage'),
path('homepage/profile/<int:pk>/', user_view.Get_Profile.as_view(), name='user-profile'),
]
base_test.html
<nav class="navbar navbar-expand-sm navbar-dark bg-dark sticky-top">
<a class="navbar-brand" href="{% url 'home' %}">Navbar</a>
<button class="navbar-toggler d-lg-none" type="button" data-toggle="collapse" data-target="#collapsibleNavId" aria-controls="collapsibleNavId"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavId">
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="{% url 'homepage' %}">Home<span class="sr-only">(current)</span></a>
</li>
{% if not user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">Log In</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'signup' %}">Sign Up</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Log Out</a>
</li>
{% endif %}
</ul>
</div>
</nav>
home_profile.html
<!-- this is the home template that displays all active users -->
{% extends 'base_test.html' %}
{% block title %} My Site | Profiles {% endblock title %}
{% block content %}
<div class="card-columns text-center padding">
{% for user in mymodel_list %}
<div class="card">
<img class="rounded-circle" src="{{user.profile.image.url}}" width=150 height=150>
<div class="card-body">
<h5 class="card-title">Full name : {{user.get_full_name}}</h5>
<p class="crad-text">Occupation/job : {{user.profile.occupation}}</p>
<a type="button" href="{% url 'user-profile' user.pk %}" style="color:whitesmoke;" class="btn btn-primary btn-sm">Profile</a>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
{% block footer %}
{% endblock footer %}
profile.html
<!-- user profile template -->
{% extends 'base_test.html' %}
{% load custom_tags %}
{% block title %} My Site | {{user.get_full_name}} {% endblock title %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-lg-8 order-lg-2 padding">
<div class="tab-content">
<div class="tab-pane active" id="profile">
<div class="row">
<div class="col-lg-12">
<h6><strong>About</strong></h6>
<p>
{{user.profile.bio}}
</p>
<hr>
</div>
<div class="col-lg-12">
<h6><strong>Skills</strong></h6>
{% for skill in user.profile.skills|split:',' %}
<span class="badge badge-primary">{{skill}}</span>
{% endfor %}
<hr>
<h6><strong>Hobbies</strong></h6>
<p>
{% for hobbie in user.profile.hobbies|split:',' %}
<span class="badge badge-success">{{hobbie}}</span>
{% endfor %}
</p>
<hr>
</div>
<!-- removes the social part -->
</div>
</div>
</div>
</div>
<div class="col-lg-4 order-lg-1 padding">
<h1 class="mb-3 text-center">{{user.get_full_name}}</h1>
<hr>
<img src="{{user.profile.image.url}}" class="mx-auto img-fluid rounded-circle d-block" alt="avatar" width=150><br>
<div class="text-center">
<h4>{{user.profile.school}}</h4>
<p><strong>Hometown :</strong> {{ user.profile.hometown}}</p>
<p><strong>Current City:</strong> {{user.profile.location}}<p>
<p><strong>Occupation/Job:</strong> {{user.profile.occupation}}<p><br>
<hr>
<button type="button" class="btn btn-outline-success btn-md">View CV</button>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block footer %}
{% endblock footer %}
I don't know What is causing this strange behaviour!!
Actually, you are mixing up with request.user and your user object for resume. You should change the context variable name from user to something else. for example:
class Get_Profile(DetailView):
"fetches user's profile"
def get(self, request, pk):
user = MyModel.objects.get(pk=pk)
return render(request, 'profile/profile.html', {'profile':user}) # <-- Here
You've used the same variable name, user, for the user whose profile you are viewing as for the one who is actually using the site. You need to pick another name.
(Also, unrelated, but you don't need to - and shouldn't - define the get method in your detail view.)

Using Instagram API to make users populate images into my Django application directly from Instagram Pictures

My use case or what I want to do is:
Users click a Upload button,
it authenticates user,
its shows Instagram images,
users select, and
user click upload button to upload images or videos (media) from
Instagram directly into my django app.
What I have done is:
Instagram integration:
pip install python-instagram
views.py:
#login_required()
def instagram_pictures(request, template='dashboard/add-instagram-pictures.html'):
user = request.user
gallery = []
gallery = Gallery.objects.filter(service_provider=user.service_provider_profile)
context = {'gallery': gallery}
return render(request, template, context)
#login_required()
def add_instagram_pictures(request, template='dashboard/add-instagram-pictures.html'):
access_token = "YOUR_ACCESS_TOKEN" # Dont know how this gets factored in for any user
client_secret = settings.SECRET_ID
api = InstagramAPI(access_token=access_token, client_secret=client_secret)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
print(media.caption.text)
template/my-gallery.html:
{% extends 'base.html' %}
{% load static %}
{% block title %}My Dashboard{% endblock %}
{% block content %}
<div class="page-header" style="background: url({% static 'img/banner1.jpg' %});">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-title">My Gallery</h1>
</div>
</div>
</div>
</div>
<div id="content">
<div class="container">
<div class="row">
{% include '_side_menu.html' %}
<div class="col-md-8 page-content">
<div class="inner-box text-center">
<a href="{% url 'dashboard:add-instagram-pictures' %}" class="btn btn-md btn-success">
<span class="fa fa-plus-circle"> Upload from Instagram</span>
</a>
<ul>
<!-- I will re-write this loop to redefine how images are rendered for the project. Maybe in Carousels-->
{% for p in photos %}
<li>{{ p.name }}</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
template/add-instagram-pictures.html:
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Gallery{% endblock %}
{% block content %}
<div class="page-header" style="background: url({% static 'img/banner1.jpg' %});">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="page-title">Add Instagram Pictures</h1>
</div>
</div>
</div>
</div>
<div id="content">
<div class="container">
<div class="row">
{% include '_side_menu.html' %}
<div class="col-md-8 page-content">
<div class="inner-box text-center">
<a href="{% url 'dashboard:my-gallery' %}" class="btn btn-md btn-success">
<span class="fa fa-chevron-circle-left"> Back to Album List</span>
</a>
</div>
</div>
</div>
</div>
</div> {% endblock %}Add
url.py:
from django.conf.urls import url, include
from dashboard.views import dashboard, my_services, add_service, my_gallery, add_gallery, bank_profile, add_bank_profile, add_instagram_pictures
def ajax_photo_upload_view(args):
pass
urlpatterns = [
url(r'^$', dashboard, {}, name='home'),
url(r'^bank-profile/$', bank_profile, {}, name='bank-profile'),
url(r'^add-bank-profile/$', add_bank_profile, name='add-bank-profile'),
url(r'^my-services/$', my_services, name='my-services'),
url(r'^add-service/$', add_service, name='add-service'),
url(r'^add-gallery/$', add_gallery, name='add-gallery'),
url(r'^my-gallery/$', my_gallery, name='my-gallery'),
url(r'^add-gallery/$', add_instagram_pictures, name='add-instagram-pictures'),
]
settings.py:
# instagram settings
CLIENT_ID = "XXXXXXXXXXXXXXXXXXXX"
SECRET_ID = "XXXXXXXXXXXXXXXXXXXX"
How do I go about my use case as I have stated, my solution is in no way closer to what I want to do.

Django is not loading template form

I don't know why is not loading the template but every time I click in an url the page auto-reload and not load the template, here is my code:
urls.py
url(r'^pedidos/add',forms.PedidoCreateView.as_view(), name="pedido_add")
forms.py
class PedidoCreateView(CreateView):
template_name = 'ventas/form_pedido.html'
model = Pedido
form_class = PedidoModelForm
success_url = 'ventas/pedidos.html'
def form_valid(self, form):
form.save(commit=True)
return super(PedidoCreateView, self).form_valid(form)
form_pedido.html
{% extends '_layouts/base.html' %}
{% load url from future %}
{% block breadcrumb%}
<li>
Pedidos
<span class="divider">
<i class="icon-angle-right"></i>
</span>
</li>
<li class="active">Nuevo Pedido</li>
{% endblock %}
{% block page_content %}
<form class ="form" id="form" method="POST" action="{{ request.path }}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Editar Empleado</h3>
</div>
<div class="modal-body">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form_errors }}
{{form.as_p}}
</div>
<div class="modal-footer">
Cerrar
<input type="submit" class="guardar btn btn-primary" value="Guardar">
</div>
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
link
<a href="{% url 'ventas:pedido_add' %}" class="btn btn-app btn-success">
For sure has to be some error that I'm not able to see now, I prove with other similar views and I don't have any problems, what could it be?