Hyperlinks in Django Quill Editor are not displaying as expected - django

Problem
I added the Quill Editor to my Django admin. When I input hyperlinks in the QuillEditor such as "www.example.com", instead of creating the hyperlink exactly as I type it, the URL will appear on the template page as "localhost:8000/plants/www.example.com". Directing me to a broken page instead of www.example.com
Context
I've read through the full quill documentation but I don't see a way to make sure hyperlinks added in the QuillEditor display without the project domain being prepended to the front of the hyperlink url.
Heres how I input the URL 'www.example.com' in the django admin:
Here is how the URL appears on the actual template page (you can see the url in the bottom left when I hover over it:
Maybe I need to edit something in the urls.py?
plants > urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('allauth.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('', include('pages.urls')),
path('plants/', include('plants.urls')),
]

Change your external links to start with "https://".
https://www.example.com

Related

Can I deploy a Django App if there is no "" (empty) url?

I'm trying to deploy a Django App with railways for the first time and I was wondering where exactly will be my landing page. So basically my urls.py looks something like this:
path('home/', views.home, name="home"),
path('blogposts/', views.blogposts, name="blogposts"),
path('posts/', views.posts, name="posts"),
After deploying my Blog website, let's say with the domain 12345xxx.com, where will I land?
You will get an error if you don't include a folder in the URL, as the URL patten won't be matched and the existance of non-admin URLs stops the default django page from showing. This will be either a 404 error or a 'Django tried these URL patterns, in this order:' type error if you have DEBUG=True on in settings.
Note that you don't have to provide a path (the path can be an empty string), and views can have multiple paths. In this case, perhaps
path('', views.home, name="home"),
path('home/', views.home, name="home_folder"),
path('blogposts/', views.blogposts, name="blogposts"),
path('posts/', views.posts, name="posts"),
would avoid an error.

How to redirect to an absolute url path in django?

I am trying to reroute to the "listing" path from the the watchlist page using the 'url' attribute in Django templates. However, the problem is that Django ignores the parts of the URL it has already used in rerouting (i.e."/watchlist") and so looks for the url with path "/watchlist/listing_title" instead of just "/listing_title", which is what I want. Is there a way to work around this?
urls.py
path("", views.index, name="index"),
path("<str:listing_title>", views.listing, name="listing"),
path("watchlist", views.watchlist, name="watchlist"),
watchlist.html
<a href={% url 'listing' listing.title %}">
It will never access watchlist, since the <str:listing_title> will match for /watchlist. You should reorder the paths, and work with:
path('', views.index, name='index'),
path('watchlist', views.watchlist, name='watchlist'),
path('<str:listing_title>', views.listing, name='listing'),
Django will enumerate over all the URL patterns top-to-bottom, and "fire" the first view that has a matching URL pattern. If we thus put <str:listing_title> first, it will match watchlist with that <str:…> path part, and thus never trigger the listing.

why does <myproject>/accounts/profile/ show the <myproject>/profile/ page

Using django-allauth, after a successful login a user is redirected to http://<myproject>/accounts/profile/... However this URL doesn't exists, but yet it still successfully shows view from http://<myproject>/profile/
settings.py
urlpatterns = [
path('', include('pages.urls')),
path('admin/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
url('album/', include('albums.urls')),
url('profile/', include('user_profile.urls')),
]
user_profile\urls.py
urlpatterns = [
path('', views.profile, name='profile'),
]
using show_urls I don't see anything for /accounts/* which would call the view.profile view
/accounts/confirm-email/ allauth.account.views.EmailVerificationSentView account_email_verification_sent
/accounts/confirm-email/<key>/ allauth.account.views.ConfirmEmailView account_confirm_email
/accounts/email/ allauth.account.views.EmailView account_email
/accounts/inactive/ allauth.account.views.AccountInactiveView account_inactive
/accounts/login/ allauth.account.views.LoginView account_login
/accounts/logout/ allauth.account.views.LogoutView account_logout
/accounts/password/change/ allauth.account.views.PasswordChangeView account_change_password
/accounts/password/reset/ allauth.account.views.PasswordResetView account_reset_password
/accounts/password/reset/done/ allauth.account.views.PasswordResetDoneView account_reset_password_done
/accounts/password/reset/key/<uidb36>-<key>/ allauth.account.views.PasswordResetFromKeyView account_reset_password_from_key
/accounts/password/reset/key/done/ allauth.account.views.PasswordResetFromKeyDoneView account_reset_password_from_key_done
/accounts/password/set/ allauth.account.views.PasswordSetView account_set_password
/accounts/signup/ allauth.account.views.SignupView account_signup
/accounts/social/connections/ allauth.socialaccount.views.ConnectionsView socialaccount_connections
/accounts/social/login/cancelled/ allauth.socialaccount.views.LoginCancelledView socialaccount_login_cancelled
/accounts/social/login/error/ allauth.socialaccount.views.LoginErrorView socialaccount_login_error
/accounts/social/signup/ allauth.socialaccount.views.SignupView socialaccount_signup
only the actual /profile/ url...
/profile/ user_profile.views.profile profile
help me to understand why /accounts/profile/ is showing the /profile/ view...
Actually redirecting to /accounts/profile/ is default behavior in django. In django global settings, it is defined as LOGIN_REDIRECT_URL. Django expects you to implement this page/url. Django django-allauth also uses same setting to redirect user after login.
If you want to redirect to any other page like /profile/, override this setting in your project settings.
LOGIN_REDIRECT_URL = '/profile/'
Or if you want django-allauth not to redirect at all set LOGIN_REDIRECT_URL = False in your settings as described here.
Your profile url path is not being limited to match only the start of the url:
url('profile/', include('user_profile.urls')),
This will match anything like gibberishprofile/ for example, including accounts/profile/. If you change the url config to
url('^profile/', include('user_profile.urls')), # note the ^ before profile
Then only profile/ will match.

Is it okay to have multiple url patterns with the same view?

I have an app that shows a list of "Issues". The main urls.py file sends /issues/ to the urls.py file in the "issues" app.
urlpatterns = [
path('', RedirectView.as_view(url='/issues/')),
path('admin/', admin.site.urls),
path('issues/', include('issues.urls')),
]
In the issues app's urls.py file I have:
path('', views.IssueListView.as_view(), name='issue-list'),
That calls the IssueListView which is a generic ListView view:
class IssueListView(generic.ListView):
model = Issue
Now, I want to add a sidebar menu with links users can click to sort the issues list by category. I understand that I can rewrite the get_queryset() method of the IssueListView to accept a kwarg, and just load all the issues if that kwarg is missing (with an if statement that checks for the presence of the kwarg, right?), but I think to do this I need to have two urlpatterns that point to the same view like:
path('', views.IssueListView.as_view(), name='issue-list'),
path('<category>', views.IssueListView.as_view(), name='issue-category-list'),
But I am wondering if that's the normal "Django way" to do it.
Thank you.
In the case you have specified, you can use the same view for both url pattern. There is nothing wrong in that.
path('', views.IssueListView.as_view(), name='issue-list'),
path('<category>', views.IssueListView.as_view(), name='issue-category-list'),

Django URL changes but doesn't render the proper view

I have a url setup with the following view (the url is in the app and the app urls are included in the project):
url(r'^details/(?P<outage_id>\d+)/$', 'outage.views.outage_details'),
def outage_details(request, outage_id=1):
outage_info = Outages.objects.filter(id=outage_id)
return render_to_response('templates/outage/details.html', {'outage_info': outage_info}, context_instance=RequestContext(request))
When I click on the link from http://localhost:8000 the url in the browser changes to http://localhost:8000/outage/details/1 as it should, but the view doesn't render the right template. The page stays the same. I don't get any errors, the url changes in the browser but the details.html template doesn't render. There is an outage in the DB with an ID of 1.
Any thoughts?
The regular expression r'^details/(?P<outage_id>\d+)/$' does not match the URL http://localhost:8000/outage/details/1. However, it should match the expression r'^outage/details/(?P<outage_id>\d+)/$'.
Perhaps, you can post your entire urls.py to find out which view is actually being called, since you don't get any errors. I suspect your home page is being called for all URLs.
Here is my url setup:
project/urls.py
urlpatterns = patterns('',
url(r'^$', 'outage.views.show_outages'),
url(r'^inventory/', include('inventory.urls')),
url(r'^outage/', include('outage.urls')),
url(r'^login', 'django.contrib.auth.views.login', {'template_name': 'templates/auth/login.html'}),
url(r'^logout', 'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^admin/', include(admin.site.urls)),
)
outage/urls.py
urlpatterns = patterns('',
url(r'^', 'outage.views.show_outages'),
url(r'^notes/(?P<outage_id>\d+)/$', 'outage.views.outage_notes', name='notes'),
)
I have since changed the details to notes, since I had another page in a different app with a details url and I didn't want it somehow confusing things.