Re: TypeError: missing 1 required positional argument (word counter app)

2019-07-10 Thread drone4four


For what it is worth, here is some of the documentation I’ve been working 
with.

I’ve referred to official Django docs for:

   - 
   
   File uploads: 
   https://docs.djangoproject.com/en/2.2/topics/http/file-uploads/
   - 
   
   Form handling with class-based views: 
   
https://docs.djangoproject.com/en/2.1/topics/class-based-views/generic-editing/
   - 
   
   HttpRequest.FILES: 
   
https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.FILES
   

Stack Overflow questions I’ve used:

   - 
   
   What does the if __name__ == "__main__": do? 
   https://stackoverflow.com/questions/419163/what-does-if-name-main-do
   - 
   
   reverse for success_url on Django Class Based View complain about 
   circular import 
   
https://stackoverflow.com/questions/31275574/reverse-for-success-url-on-django-class-based-view-complain-about-circular-impor
   - 
   
   How can I get uploaded text file in view through Django? 
   
https://stackoverflow.com/questions/39436612/how-can-i-get-uploaded-text-file-in-view-through-django

   - 
   
   How can i get the file name from request.FILES? 
   
https://stackoverflow.com/questions/3111779/how-can-i-get-the-file-name-from-request-files
   - 
   
   How to reverse_lazy to a view/url with variable? 
   
https://stackoverflow.com/questions/46184193/how-to-reverse-lazy-to-a-view-url-with-variable
   


On Wednesday, July 10, 2019 at 1:13:16 PM UTC-4, drone4four wrote:
>
> I’ve got a Python script which counts and prints the number of words in a 
> text file. The script runs beautifully. It takes a public domain book (a 
> text file such as Alice and Wonderland) which then counts the top 10 most 
> used words (but which also filters out stopwords).  See here for some of my 
> previous work: 
> https://stackoverflow.com/questions/56436291/filtering-stop-words-out-of-a-large-text-file-using-package-nltk-corpus
>
>
> Now I am trying to ‘port’ this Python shell script to Django. My intention 
> for this project is to have the Django app count the number of words in a 
> blog post. But for now I’m still using Alice and Wonderland in .txt format.
>
>
> I’ve encountered some issues with my local dev server running but serving 
> me a series of name errors involving my views module when I navigate to the 
> url. I was hoping some of you could provide some insight.
>
>
> When I run the server and navigate to http://127.0.0.1:8000/seth/, this 
> is the error showing in my web browser pointing to the issue at hand: 
> https://pastebin.com/52x2c4iN
>
>
> Here is the traceback from my local Django dev server in my shell: 
> https://pastebin.com/a8PTcRki
>
>
> The file with the most problems is my counters/views.py (current app 
> only): 
> https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/views.py
>
>
> I realize that the problem is with the way the text variable is tossed 
> around. I probably should not be invoking global variables as I do at lines 
> 24, 38, 39 in my views model (above). Furthermore, out of the Udemy course 
> material I’ve watched and in the official Django docs I’ve read, I’ve never 
> seen a views.py which uses main() for calling functions. I realize I am 
> sort of departing from Django norms here. What might you people recommend I 
> try instead?
>
>
> Here is counters/models.py:
>
>
> https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/models.py
>
>
> counters/forms.py: 
> https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/forms.py
>  
>
>
> urls.py in parent project directory: 
> https://github.com/Angeles4four/CC_Redact_Iter2/blob/master/CC_Redact_Iter2/urls.py
>
>
> Here is Alice and Wonderland in .txt format: 
> https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/Alice.txt
>
>
> What other comments might you have about my code, in particular the 
> views.py linked to above?
>
>
> I’m running Django 2.2 and Python 3.7 on Manjaro.
>
>
> Pull requests on GitHub are welcome although I realize if asking for pull 
> requests like this might not be reasonable for most of you but I thought 
> I’d say as always, just in case a kind and generous forum contributor has 
> time on their hands. Requirements.txt is included on the master branch.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8d7c1b44-b262-46ee-b83b-0b43ba011847%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


TypeError: missing 1 required positional argument (word counter app)

2019-07-10 Thread drone4four


I’ve got a Python script which counts and prints the number of words in a 
text file. The script runs beautifully. It takes a public domain book (a 
text file such as Alice and Wonderland) which then counts the top 10 most 
used words (but which also filters out stopwords).  See here for some of my 
previous work: 
https://stackoverflow.com/questions/56436291/filtering-stop-words-out-of-a-large-text-file-using-package-nltk-corpus


Now I am trying to ‘port’ this Python shell script to Django. My intention 
for this project is to have the Django app count the number of words in a 
blog post. But for now I’m still using Alice and Wonderland in .txt format.


I’ve encountered some issues with my local dev server running but serving 
me a series of name errors involving my views module when I navigate to the 
url. I was hoping some of you could provide some insight.


When I run the server and navigate to http://127.0.0.1:8000/seth/, this is 
the error showing in my web browser pointing to the issue at hand: 
https://pastebin.com/52x2c4iN


Here is the traceback from my local Django dev server in my shell: 
https://pastebin.com/a8PTcRki


The file with the most problems is my counters/views.py (current app only): 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/views.py


I realize that the problem is with the way the text variable is tossed 
around. I probably should not be invoking global variables as I do at lines 
24, 38, 39 in my views model (above). Furthermore, out of the Udemy course 
material I’ve watched and in the official Django docs I’ve read, I’ve never 
seen a views.py which uses main() for calling functions. I realize I am 
sort of departing from Django norms here. What might you people recommend I 
try instead?


Here is counters/models.py:

https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/models.py


counters/forms.py: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/forms.py 


urls.py in parent project directory: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/master/CC_Redact_Iter2/urls.py


Here is Alice and Wonderland in .txt format: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/Alice.txt


What other comments might you have about my code, in particular the 
views.py linked to above?


I’m running Django 2.2 and Python 3.7 on Manjaro.


Pull requests on GitHub are welcome although I realize if asking for pull 
requests like this might not be reasonable for most of you but I thought 
I’d say as always, just in case a kind and generous forum contributor has 
time on their hands. Requirements.txt is included on the master branch.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9665256-b0e7-46fc-8b32-0cca19265acc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Novice questions about Pagination syntax and classes in general

2019-06-01 Thread drone4four


As part of the official Django doc on Pagination 
,
 
take a look at the listing function:

def listing(request):
contact_list = Contacts.objects.all()
paginator = Paginator(contact_list, 25) # Show 25 contacts per page


My two questions are:

   1. 
   
   Is it possible to return more than one value when a function is assigned 
   to a variable, like at line 3? 
   2. 
   
   At line 2, is `objects` a method within the Contacts class? If so, where 
   is the Contacts class defined? It’s not imported at the top of the example 
   views.py also in that Django doc above where I got this code sample.
   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3540a14b-ef8a-4de3-ad59-858ca1c2a7c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django module view has no attribute?

2019-04-02 Thread drone4four


Thank you Lloyd:

You are right that my import statements are written inside my urls.py in 
such away that they override each other, confusing Django. I appreciate 
your advice, but with all due respect, a slightly more Pythonic approach 
would be this:

“””

from django.contrib import admin

from django.urls import path, re_path

# from . import views

from posts.views import *

from redactors.views import *

from counters.views import *

urlpatterns = [

 path('admin/', admin.site.urls),

 re_path('^$', home, name='home'),

 re_path('^result/', result, name='result'),

 re_path('^seth/', counters, name='seth'),

 re_path('^james/', posts, name='james'),

 re_path('^simon/', redactors, name='simon'),

]

“””

I find the re_path’s as they appear here to be more human readable than 
single alphabetical letters.

To explain with clarity, lines 4,5,6 import all functions from within the 
app directories and within each views.py package.  

Also, Django 2.0 now requires regex paths in url patterns to use the 
re_path() function as describe here: 
https://docs.djangoproject.com/en/2.2/ref/urls/#re-path

My Django server now runs without reporting an issue at system check.

To answer your question, Joel: Yes, there is a function named posts inside 
views.py.

On Monday, April 1, 2019 at 10:30:45 PM UTC-4, Lloyd Dube wrote:
>
> I don't know the contents of the course you are taking, but it looks like 
> the last import of views, which is "from counters import views" is 
> overriding all the others and in it you have not defined a "posts" view.
>
> 1. You could solve this by aliasing your imports, e.g.:
> ```
> from django.contrib import admin
> from django.urls import path
> # from . import views as a
> from posts import views as b
> from redactors import views as c
> *from counters import views as d*
> urlpatterns = [
>   path('admin/', admin.site.urls),
>   path('^$', a.home, name='home'),
>   path('^b/', views.result, name='result'),
>   path('^b/', views.counters, name='seth'),
>   *path('^d/', views.posts, name='james'),*
>   path('^d/', views.redactors, name='simon'),
> ]
> ```
>
> ... although this is not what you should be doing with django.
>
> 2. (much better) you could use the `include` function of the django.urls 
> module and pass in the string representation of each urls module's name. 
> You would not need to import each app's urls.py module for this.
>
> ```
> from django.urls import *include*, path
>
> urlpatterns = [
>   path('admin/', admin.site.urls),
>   path('^james', *include*('posts.urls')),
> ]
> ```
>
> ...etc.
>
> I would recommend doing a short Python tutorial to understand some key 
> basics, such as how imports work (
> https://www.w3schools.com/python/default.asp) and doing the official 
> Django "Getting Started" guide and tutorial (you can find the latest 
> version on https://www.djangoproject.com/start/).
>
>
> Kind regards,
> Sithembewena
>
>
> *Sent with Shift 
> <https://tryshift.com/?utm_source=SentWithShift_campaign=Sent%20with%20Shift%20Signature_medium=Email%20Signature_content=General%20Email%20Group>*
>
> On Tue, Apr 2, 2019 at 3:59 AM drone4four  > wrote:
>
>> I’m taking a Udemy course by Nick Walter and rather than copying line by 
>> line, I’m trying to branch out and experiment on my own.  
>>
>> The purpose of the website I am creating is for a small blog, with the 
>> ability to redact string input (in an HTML form) from the user. There is 
>> also a word counter for the body content of the blog.
>>
>> I got Django running but as soon as I started adding the code I wrote, 
>> Django stopped running properly. 
>>
>> Here is the traceback in full: https://pastebin.com/8HtdNwPP 
>>
>> The main issue shows at the bottom:
>>
>> File 
>>> "/home//dev/projects/python/2018-and-2019/CC_Redact_Iter2/CC_Redact_Iter2/urls.py",
>>>  
>>> line 28, in 
>>>* path('^james/', views.posts, name='james'),*
>>> *AttributeError: module 'counters.views' has no attribute 'posts’*
>>
>>
>>
>> Based on this traceback, I gather I have probably misnamed a function or 
>> a file name or template but I can’t for the life of me figure which one or 
>> where. 
>>
>> My entire source code repo can be found here: 
>> https://github.com/Angeles4four/CC_Redact_Iter2
>>
>> Here are some of the relevant files involved.
>>
>> urls.py:
>>
>> from django.contrib import admin
>>> from django.urls import path
>>> # from . import views
>>> from posts import views
>>> from redactors import views
>>> from count

Django module view has no attribute?

2019-04-01 Thread drone4four


I’m taking a Udemy course by Nick Walter and rather than copying line by 
line, I’m trying to branch out and experiment on my own.  

The purpose of the website I am creating is for a small blog, with the 
ability to redact string input (in an HTML form) from the user. There is 
also a word counter for the body content of the blog.

I got Django running but as soon as I started adding the code I wrote, 
Django stopped running properly. 

Here is the traceback in full: https://pastebin.com/8HtdNwPP 

The main issue shows at the bottom:

File 
> "/home//dev/projects/python/2018-and-2019/CC_Redact_Iter2/CC_Redact_Iter2/urls.py",
>  
> line 28, in 
>* path('^james/', views.posts, name='james'),*
> *AttributeError: module 'counters.views' has no attribute 'posts’*



Based on this traceback, I gather I have probably misnamed a function or a 
file name or template but I can’t for the life of me figure which one or 
where. 

My entire source code repo can be found here: 
https://github.com/Angeles4four/CC_Redact_Iter2

Here are some of the relevant files involved.

urls.py:

from django.contrib import admin
> from django.urls import path
> # from . import views
> from posts import views
> from redactors import views
> from counters import views
> urlpatterns = [
>   path('admin/', admin.site.urls),
>   path('^$', views.home, name='home'),
>   path('^result/', views.result, name='result'),
>   path('^seth/', views.counters, name='seth'),
>   path('^james/', views.posts, name='james'),
>   path('^james/', views.redactors, name='simon'),
> ]



counters/views.py:

from django.http import HttpResponse
> from django.shortcuts import render
> def home(request):
>   if 'ccEntry' in request.GET:
>   number = request.GET['ccEntry']
>   redacted_num = '   {}'.format(number[-4:])
>   return render(request, 'result.html', {'number':number, 
> 'redacted_num':redacted_num})
>   else:
>   return render(request, 'home.html')
> def result(request):
>return render(request, 'result.html')
> def counters(request):
>   return render(request, 'counters/james.html')


Here is my file tree: https://imgur.com/a/BUTKKEH

Contents of requirements.txt:

> Django==2.0.13
> Pillow==5.4.1
> psycopg2==2.7.7
> psycopg2-binary==2.7.7
> pytz==2018.9



If there are other files in my project that you wish to view, you can click 
through the file tree as it appears on GitHub (linked to above).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/353c83b5-1f37-4e23-b6c7-f488cb05805e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Separating remote vs local settings.py parameters - - “EMAIL”?

2019-03-16 Thread drone4four


So the remote server production email contact information could be 
different from the developer’s testcase email contact info?

I’ve taken a closer look at the “email-backend” section of the Django docs 
that you’ve linked to, Ahmed. I see Django supports email settings.  I 
don’t really understand what these EMAIL parameters would be used for. For 
example, EMAIL_BACKEND says:

Default: 'django.core.mail.backends.smtp.EmailBackend 
> <https://docs.djangoproject.com/en/2.1/topics/email/#django.core.mail.backends.smtp.EmailBackend>
> '
> The backend to use for sending emails. For the list of available backends 
> see Sending email <https://docs.djangoproject.com/en/2.1/topics/email/>.


I followed these two links and it is still not clear to me: Are these email 
settings only used if I implement SMTP or other email services? 

Would it be OK for me to just exclude altogether “EMAIL_*” until I reach a 
point when there is a need for an SMTP server (which will probably be never 
for the project I am working on)?


On Friday, March 15, 2019 at 9:27:41 PM UTC-4, Ahmed Ishtiaque wrote:
>
> The character "*" represents "wildcard". Here is the real reason why the 
> instructor puts it that way: 
> https://docs.djangoproject.com/en/2.1/ref/settings/#email-backend
>
> There are a lot of variables that contain the 'EMAIL_' prefix, which is 
> why the instructor wrote it that way.
>
> On Fri, Mar 15, 2019 at 8:16 PM drone4four  > wrote:
>
>> If you take a look at this gist provided by a Udemy instructor and at 
>> this specific location 
>> <https://gist.github.com/bradtraversy/cfa565b879ff1458dba08f423cb01d71#local-settings-setup>,
>>  
>> here he wisely recommends separating important local development 
>> configuration parameters, such as SECRET _KEY. Of course everyone knows how 
>> stupid and foolish it would be to share the SECRET_KEY publicly on GitHub 
>> and then to use it in your production environment. 
>>
>>
>> So here is the list of parameters to place in the separate remote 
>> settings.py as it appears in that gist linked to above:
>>
>>
>>- 
>>
>>SECRET_KEY
>>- 
>>
>>ALLOWED_HOSTS
>>- 
>>
>>DATABASES
>>- 
>>
>>DEBUG
>>- 
>>
>>EMAIL_*
>>
>>
>> If you look at the last one, it says: “EMAIL_*”. What do you people think 
>> the “_*” suffix? Is this standard for settings.py configurations? Or would 
>> you people think this is just a glaring typo on the side of the instructor?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/fa499e85-b7cd-43a1-b21a-e8d6c665e498%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/fa499e85-b7cd-43a1-b21a-e8d6c665e498%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2d0fca8e-3750-4fd0-8b36-5383b29e3191%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Separating remote vs local settings.py parameters - - “EMAIL”?

2019-03-15 Thread drone4four


If you take a look at this gist provided by a Udemy instructor and at this 
specific location 
,
 
here he wisely recommends separating important local development 
configuration parameters, such as SECRET _KEY. Of course everyone knows how 
stupid and foolish it would be to share the SECRET_KEY publicly on GitHub 
and then to use it in your production environment. 


So here is the list of parameters to place in the separate remote 
settings.py as it appears in that gist linked to above:


   - 
   
   SECRET_KEY
   - 
   
   ALLOWED_HOSTS
   - 
   
   DATABASES
   - 
   
   DEBUG
   - 
   
   EMAIL_*
   

If you look at the last one, it says: “EMAIL_*”. What do you people think 
the “_*” suffix? Is this standard for settings.py configurations? Or would 
you people think this is just a glaring typo on the side of the instructor?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fa499e85-b7cd-43a1-b21a-e8d6c665e498%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


rsync vs git for Django development? + Project directory location?

2019-03-15 Thread drone4four
Have two questions.

To manage development of a Django project, when interfacing local changes 
and mirroring them to my remote webserver, would you people recommend using 
rsync or git? I have a little experience with both. I've been using rsync 
to mirror basic HTML and CSS changes from my local host to my remote Apache 
public_html directory for a while now. I was thinking of using rsync for 
transferring changes to my webserver but in one of the courses I am taking, 
the instructor uses git and GitHub. I’m not sure if using git is overkill 
or not best practices. What would you people recommend?

Whether I go with git or rsync, I also need to make a decision about where 
to place my Django project folder on my VPS. One of the guides I am using, 
titled, “How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 
18.04 
”
 
suggests putting it inside the user’s home folder. I gather this isn’t the 
most secure option. It’s also not a good idea to place the Django project 
folder inside the Apache public_html folder, am I right? I read both these 
things somewhere a while ago but I can’t recall exactly where. Anyways, to 
set the record straight, where would you people recommend I place my Django 
project folder on my VPS?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/994e80b8-0c4d-439c-b0e3-636b8e4f00e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-14 Thread drone4four


Thank you Ahmed for this clarification. This makes sense.

I have two further questions for you (or anyone else still reading this 
thread):


   1. 
   
   Is there a way of checking for the presence of the data with GET which 
   is more Pythonic and aligns with better practices?
   


   1. 
   
   On an unrelated note, I attempted to reduce my issue in this testcase as 
   best I could. I think I did an OK job. But would there be a better way for 
   me to ask my question to attract more responses? What would any of you 
   recommend in terms of advice for me to refine and refine the way I ask 
   similar questions in the future on this message board?
   


On Thursday, March 14, 2019 at 2:13:35 PM UTC-4, Ahmed Ishtiaque wrote:
>
> When a user requests your home page's URL the first time in order to load 
> your home.html file, the GET request they send to your server does not 
> contain the 'ccEntry' parameter, which raised the MultiValueDictKeyError 
> whenever your view was executing. However, in your edited view, you take 
> care of that by first checking whether the GET request contains 'ccEntry', 
> which is why it is working correctly now. 
>
> On Thu, Mar 14, 2019 at 9:57 AM drone4four  > wrote:
>
>> I’ve discovered a ‘hack’ to correct the issue. I committed and pushed my 
>> changes up to my GitHub repo for those curious enough to try it out 
>> yourself. 
>>
>> My problem now is that I don’t really understand why it works. Here I 
>> will explain what I do know and then my ask would be for you people to fill 
>> in the gaps in my explanation.  First I share my working code. 
>>
>> Here is my views.py which includes the relevant function I use:
>>
>> from django.http import HttpResponse
>>
>>
>>
>> from django.shortcuts import render
>>
>>
>> def home(request):
>>
>>if 'ccEntry' in request.GET:
>>
>>number = request.GET['ccEntry']
>>
>>redacted_num = '   {}'.format(number[-4:])
>>
>>return render(request, 'home.html', {'number':number, 
>> 'redacted_num':redacted_num})
>>
>>else:
>>
>>return render(request, 'home.html')
>>
>>
>>
>>
>> Here is my lucid, cerebral explanation of the above Python code in plain 
>> English: At line 4 I am defining the `home` function. Then there is a 
>> conditional referring to the ‘ccEntry’ string inside the template. If 
>> ccEntry is present in the GET request, then a `number` variable is declared 
>> based on the user input on the web page. Then a `redacted_num` variable is 
>> declared which will appear as a string (‘   ’ with the last 4 
>> characters lopped off (the slice). If all of the above is in order, then 
>> the render function will be returned:
>>
>>- 
>>
>>with the standard request,
>>- 
>>
>>with reference to the home.html template, 
>>- 
>>
>>along with a dictionary with a ‘number’ string matching up with the 
>>`number` variable. Ditto for the redact_num.
>>
>> However if the above condition is false, then the render function will 
>> return the standard request and home.html template without a dictionary. 
>> That’s pretty much everything I understand.  
>>
>> I’m not sure why a conditional as it appears above is necessary. 
>>
>> Would someone here care to explain, if you can?
>>
>>
>> On Thursday, March 7, 2019 at 4:05:28 PM UTC-5, drone4four wrote:
>>>
>>> This is a long shot, but I thought I would share a link to my source 
>>> code hosted on GitHub with a requirements.txt included. If any of you would 
>>> like to test this out yourself, I am accepting pull requests. Here it is: 
>>> https://github.com/Angeles4four/CC_Redact
>>>
>>>
>>> On Thursday, March 7, 2019 at 4:03:37 PM UTC-5, drone4four wrote:
>>>>
>>>> I am taking a course on Udemy and the instructor doesn’t include a 
>>>> method attribute in the form tag.  But as you suggested, Deepak, I went 
>>>> ahead and added method="get" to my form tag in my home.html template. So 
>>>> line 7 now reads: 
>>>>
>>>> I am still encountering the MultiValueDictKeyError. 
>>>>
>>>> Here is the traceback again:
>>>>
>>>> MultiValueDictKeyError at /
>>>>
>>>> 'ccEntry'
>>>>
>>>> Request Method: GET
>>>>
>>>> Request URL: http://127.0.0.1:8000/
>>>>
>>>> Django Versi

Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-14 Thread drone4four


I’ve discovered a ‘hack’ to correct the issue. I committed and pushed my 
changes up to my GitHub repo for those curious enough to try it out 
yourself. 

My problem now is that I don’t really understand why it works. Here I will 
explain what I do know and then my ask would be for you people to fill in 
the gaps in my explanation.  First I share my working code. 

Here is my views.py which includes the relevant function I use:

from django.http import HttpResponse



from django.shortcuts import render


def home(request):

   if 'ccEntry' in request.GET:

   number = request.GET['ccEntry']

   redacted_num = '   {}'.format(number[-4:])

   return render(request, 'home.html', {'number':number, 'redacted_num':
redacted_num})

   else:

   return render(request, 'home.html')




Here is my lucid, cerebral explanation of the above Python code in plain 
English: At line 4 I am defining the `home` function. Then there is a 
conditional referring to the ‘ccEntry’ string inside the template. If 
ccEntry is present in the GET request, then a `number` variable is declared 
based on the user input on the web page. Then a `redacted_num` variable is 
declared which will appear as a string (‘   ’ with the last 4 
characters lopped off (the slice). If all of the above is in order, then 
the render function will be returned:

   - 
   
   with the standard request,
   - 
   
   with reference to the home.html template, 
   - 
   
   along with a dictionary with a ‘number’ string matching up with the 
   `number` variable. Ditto for the redact_num.
   
However if the above condition is false, then the render function will 
return the standard request and home.html template without a dictionary. 
That’s pretty much everything I understand.  

I’m not sure why a conditional as it appears above is necessary. 

Would someone here care to explain, if you can?


On Thursday, March 7, 2019 at 4:05:28 PM UTC-5, drone4four wrote:
>
> This is a long shot, but I thought I would share a link to my source code 
> hosted on GitHub with a requirements.txt included. If any of you would like 
> to test this out yourself, I am accepting pull requests. Here it is: 
> https://github.com/Angeles4four/CC_Redact
>
>
> On Thursday, March 7, 2019 at 4:03:37 PM UTC-5, drone4four wrote:
>>
>> I am taking a course on Udemy and the instructor doesn’t include a method 
>> attribute in the form tag.  But as you suggested, Deepak, I went ahead and 
>> added method="get" to my form tag in my home.html template. So line 7 now 
>> reads: 
>>
>> I am still encountering the MultiValueDictKeyError. 
>>
>> Here is the traceback again:
>>
>> MultiValueDictKeyError at /
>>
>> 'ccEntry'
>>
>> Request Method: GET
>>
>> Request URL: http://127.0.0.1:8000/
>>
>> Django Version: 2.0.2
>>
>> Exception Type: MultiValueDictKeyError
>>
>> Exception Value: 
>>
>> 'ccEntry'
>>
>> Exception Location: 
>> /home//.local/lib/python3.7/site-packages/django/utils/datastructures.py
>>  
>> in __getitem__, line 79
>>
>> Python Executable: /usr/sbin/python
>>
>> Python Version: 3.7.2
>>
>> Python Path: 
>>
>>
>> ['/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt',
>>
>> '/usr/lib/python37.zip',
>>
>> '/usr/lib/python3.7',
>>
>> '/usr/lib/python3.7/lib-dynload',
>>
>> '/home//.local/lib/python3.7/site-packages',
>>
>> '/usr/lib/python3.7/site-packages',
>>
>> '/usr/lib/python3.7/site-packages/setuptools-40.6.2-py3.7.egg']
>>
>> Server time: Thu, 7 Mar 2019 20:11:44 +
>>
>> Environment:
>>
>>
>> Request Method: GET
>>
>> Request URL: http://127.0.0.1:8000/
>>
>> Django Version: 2.0.2
>>
>> Python Version: 3.7.2
>>
>> Installed Applications:
>>
>> ['django.contrib.admin',
>>
>> 'django.contrib.auth',
>>
>> 'django.contrib.contenttypes',
>>
>> 'django.contrib.sessions',
>>
>> 'django.contrib.messages',
>>
>> 'django.contrib.staticfiles']
>>
>> Installed Middleware:
>>
>> ['django.middleware.security.SecurityMiddleware',
>>
>> 'django.contrib.sessions.middleware.SessionMiddleware',
>>
>> 'django.middleware.common.CommonMiddleware',
>>
>> 'django.middleware.csrf.CsrfViewMiddleware',
>>
>> 'django.contrib.auth.middleware.AuthenticationMiddleware',
>>
>> 'django.contrib.messages.middleware.MessageMiddleware',
>>
>> 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-07 Thread drone4four


This is a long shot, but I thought I would share a link to my source code 
hosted on GitHub with a requirements.txt included. If any of you would like 
to test this out yourself, I am accepting pull requests. Here it is: 
https://github.com/Angeles4four/CC_Redact


On Thursday, March 7, 2019 at 4:03:37 PM UTC-5, drone4four wrote:
>
> I am taking a course on Udemy and the instructor doesn’t include a method 
> attribute in the form tag.  But as you suggested, Deepak, I went ahead and 
> added method="get" to my form tag in my home.html template. So line 7 now 
> reads: 
>
> I am still encountering the MultiValueDictKeyError. 
>
> Here is the traceback again:
>
> MultiValueDictKeyError at /
>
> 'ccEntry'
>
> Request Method: GET
>
> Request URL: http://127.0.0.1:8000/
>
> Django Version: 2.0.2
>
> Exception Type: MultiValueDictKeyError
>
> Exception Value: 
>
> 'ccEntry'
>
> Exception Location: 
> /home//.local/lib/python3.7/site-packages/django/utils/datastructures.py
>  
> in __getitem__, line 79
>
> Python Executable: /usr/sbin/python
>
> Python Version: 3.7.2
>
> Python Path: 
>
>
> ['/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt',
>
> '/usr/lib/python37.zip',
>
> '/usr/lib/python3.7',
>
> '/usr/lib/python3.7/lib-dynload',
>
> '/home//.local/lib/python3.7/site-packages',
>
> '/usr/lib/python3.7/site-packages',
>
> '/usr/lib/python3.7/site-packages/setuptools-40.6.2-py3.7.egg']
>
> Server time: Thu, 7 Mar 2019 20:11:44 +
>
> Environment:
>
>
> Request Method: GET
>
> Request URL: http://127.0.0.1:8000/
>
> Django Version: 2.0.2
>
> Python Version: 3.7.2
>
> Installed Applications:
>
> ['django.contrib.admin',
>
> 'django.contrib.auth',
>
> 'django.contrib.contenttypes',
>
> 'django.contrib.sessions',
>
> 'django.contrib.messages',
>
> 'django.contrib.staticfiles']
>
> Installed Middleware:
>
> ['django.middleware.security.SecurityMiddleware',
>
> 'django.contrib.sessions.middleware.SessionMiddleware',
>
> 'django.middleware.common.CommonMiddleware',
>
> 'django.middleware.csrf.CsrfViewMiddleware',
>
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
>
> 'django.contrib.messages.middleware.MessageMiddleware',
>
> 'django.middleware.clickjacking.XFrameOptionsMiddleware']
>
>
>
> Traceback:
>
> File 
> "/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
>  
> in __getitem__
>
>  77. list_ = super().__getitem__(key)
>
> During handling of the above exception ('ccEntry'), another exception 
> occurred:
>
> File 
> "/home//.local/lib/python3.7/site-packages/django/core/handlers/exception.py"
>  
> in inner
>
>  35. response = get_response(request)
>
> File 
> "/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py"
>  
> in _get_response
>
>  128. response = self.process_exception_by_middleware(e, 
> request)
>
> File 
> "/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py"
>  
> in _get_response
>
>  126. response = wrapped_callback(request, *callback_args, 
> **callback_kwargs)
>
> File 
> "/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt/first_project_attempt/views.py"
>  
> in home
>
>  5. number = request.GET['ccEntry']
>
> File 
> "/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
>  
> in __getitem__
>
>  79. raise MultiValueDictKeyError(key)
>
> Exception Type: MultiValueDictKeyError at /
>
> Exception Value: 'ccEntry'
>
>
> Request information
>
> USER
>
> AnonymousUser
>
> GET
>
> No GET data
>
> POST
>
> No POST data
>
> FILES
>
> No FILES data
>
>
> On Thursday, March 7, 2019 at 2:50:00 PM UTC-5, Deepak Chhitarka wrote:
>>
>> In your home.html template, you forgot to write method="get" . Which I 
>> think is causing the problem here.
>>
>> On Fri 8 Mar, 2019, 12:03 AM Matthew Pava,  wrote:
>>
>>> Please just paste the error in the email message. The error message that 
>>> you have mentions a ‘method’ object, which is not present in the code that 
>>> you have sent to us.  That would be where the problem is.
>>>
>>>  
>>>
>>>  
>>>
>>>  
>>>
>>> *From:* django...@googlegroups.com [mai

Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-07 Thread drone4four


I am taking a course on Udemy and the instructor doesn’t include a method 
attribute in the form tag.  But as you suggested, Deepak, I went ahead and 
added method="get" to my form tag in my home.html template. So line 7 now 
reads: 

I am still encountering the MultiValueDictKeyError. 

Here is the traceback again:

MultiValueDictKeyError at /

'ccEntry'

Request Method: GET

Request URL: http://127.0.0.1:8000/

Django Version: 2.0.2

Exception Type: MultiValueDictKeyError

Exception Value: 

'ccEntry'

Exception Location: 
/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py 
in __getitem__, line 79

Python Executable: /usr/sbin/python

Python Version: 3.7.2

Python Path: 

['/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt',

'/usr/lib/python37.zip',

'/usr/lib/python3.7',

'/usr/lib/python3.7/lib-dynload',

'/home//.local/lib/python3.7/site-packages',

'/usr/lib/python3.7/site-packages',

'/usr/lib/python3.7/site-packages/setuptools-40.6.2-py3.7.egg']

Server time: Thu, 7 Mar 2019 20:11:44 +

Environment:


Request Method: GET

Request URL: http://127.0.0.1:8000/

Django Version: 2.0.2

Python Version: 3.7.2

Installed Applications:

['django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.staticfiles']

Installed Middleware:

['django.middleware.security.SecurityMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.middleware.common.CommonMiddleware',

'django.middleware.csrf.CsrfViewMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.contrib.messages.middleware.MessageMiddleware',

'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File 
"/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
 
in __getitem__

 77. list_ = super().__getitem__(key)

During handling of the above exception ('ccEntry'), another exception 
occurred:

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/exception.py"
 
in inner

 35. response = get_response(request)

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py" 
in _get_response

 128. response = self.process_exception_by_middleware(e, 
request)

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py" 
in _get_response

 126. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

File 
"/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt/first_project_attempt/views.py"
 
in home

 5. number = request.GET['ccEntry']

File 
"/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
 
in __getitem__

 79. raise MultiValueDictKeyError(key)

Exception Type: MultiValueDictKeyError at /

Exception Value: 'ccEntry'


Request information

USER

AnonymousUser

GET

No GET data

POST

No POST data

FILES

No FILES data


On Thursday, March 7, 2019 at 2:50:00 PM UTC-5, Deepak Chhitarka wrote:
>
> In your home.html template, you forgot to write method="get" . Which I 
> think is causing the problem here.
>
> On Fri 8 Mar, 2019, 12:03 AM Matthew Pava,  > wrote:
>
>> Please just paste the error in the email message. The error message that 
>> you have mentions a ‘method’ object, which is not present in the code that 
>> you have sent to us.  That would be where the problem is.
>>
>>  
>>
>>  
>>
>>  
>>
>> *From:* django...@googlegroups.com  [mailto:
>> django...@googlegroups.com ] *On Behalf Of *drone4four
>> *Sent:* Thursday, March 7, 2019 11:29 AM
>> *To:* Django users
>> *Subject:* Re: Django credit card redaction app - - 
>> MultiValueDictKeyError
>>
>>  
>>
>> Thanks, Sam for the help.
>>
>>  
>>
>> You wrote:
>>
>>  
>>
>> I would be careful how you pass the data on get, somewhere in your front 
>> end code you are probably not passing the data through as you expected. 
>> Instead of using .GET, use .GET.get to get your data. This will either 
>> return the value you want, or none.
>>
>>  
>>
>> I looked up GET.get Django and found an SO post titled, “Django 
>> request.GET 
>> <https://stackoverflow.com/questions/3500859/django-request-get>” which 
>> has quite a few up votes. Based on that SO answer, In my views.py I changed 
>> the line (where I declare the number variable) from `number = 
>> request.GET['ccEntry']` to `number = request.GET.get['ccEntry', None]`  
>>
>>  
>>
>> That gives a diff

Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-07 Thread drone4four
Here is the error, traceback and Request information:

MultiValueDictKeyError at /

'ccEntry'

Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.0.2
Exception Type: MultiValueDictKeyError
Exception Value: 

'ccEntry'

Exception Location: 
/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py 
in __getitem__, line 79
Python Executable: /usr/sbin/python
Python Version: 3.7.2
Python Path: 

['/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt',
 '/usr/lib/python37.zip',
 '/usr/lib/python3.7',
 '/usr/lib/python3.7/lib-dynload',
 '/home//.local/lib/python3.7/site-packages',
 '/usr/lib/python3.7/site-packages',
 '/usr/lib/python3.7/site-packages/setuptools-40.6.2-py3.7.egg']

Server time:



Thu, 7 Mar 2019 17:39:40 +


Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 2.0.2
Python Version: 3.7.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File 
"/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
 
in __getitem__
  77. list_ = super().__getitem__(key)

During handling of the above exception ('ccEntry'), another exception 
occurred:

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/exception.py"
 
in inner
  35. response = get_response(request)

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py" 
in _get_response
  128. response = self.process_exception_by_middleware(e, 
request)

File 
"/home//.local/lib/python3.7/site-packages/django/core/handlers/base.py" 
in _get_response
  126. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

File 
"/home//dev/projects/python/2018-and-2019/cel2fah-original_with_CC-redact-project-_Django202/first_project_attempt/first_project_attempt/views.py"
 
in home
  5. number = request.GET['ccEntry']

File 
"/home//.local/lib/python3.7/site-packages/django/utils/datastructures.py"
 
in __getitem__
  79. raise MultiValueDictKeyError(key)

Exception Type: MultiValueDictKeyError at /
Exception Value: 'ccEntry'

Request informationUSER

AnonymousUser
GET

No GET data
POST

No POST data
FILES
No FILES data

On Thursday, March 7, 2019 at 1:34:17 PM UTC-5, Matthew Pava wrote:
>
> Please just paste the error in the email message. The error message that 
> you have mentions a ‘method’ object, which is not present in the code that 
> you have sent to us.  That would be where the problem is.
>
>  
>
>  
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *drone4four
> *Sent:* Thursday, March 7, 2019 11:29 AM
> *To:* Django users
> *Subject:* Re: Django credit card redaction app - - MultiValueDictKeyError
>
>  
>
> Thanks, Sam for the help.
>
>  
>
> You wrote:
>
>  
>
> I would be careful how you pass the data on get, somewhere in your front 
> end code you are probably not passing the data through as you expected. 
> Instead of using .GET, use .GET.get to get your data. This will either 
> return the value you want, or none.
>
>  
>
> I looked up GET.get Django and found an SO post titled, “Django 
> request.GET 
> <https://stackoverflow.com/questions/3500859/django-request-get>” which 
> has quite a few up votes. Based on that SO answer, In my views.py I changed 
> the line (where I declare the number variable) from `number = 
> request.GET['ccEntry']` to `number = request.GET.get['ccEntry', None]`  
>
>  
>
> That gives a different error (a type error this time): 
> https://pastebin.com/L81LVtzi 
>
>  
>
> You also mentioned my front end. I had included the template in my 
> original post. I have since refined it so it is more readable. Here is my 
> improved home.html template:
>
>  
>
> 
>
>
>
> 
>
>   Search 
>
> 
>
>   
>
> 
>
> 
>
>  
>
>Enter your fake Chuckee Cheese Neptune credit card number!
>
>
>
>   Must be a 16 digit number. 
>
>
>
>  
>
> 
>
>Original Card Number:
>
>{{ number }}
>
>Redacted Card Number:
>
>

Re: Django credit card redaction app - - MultiValueDictKeyError

2019-03-07 Thread drone4four


Thanks, Sam for the help.

You wrote:

I would be careful how you pass the data on get, somewhere in your front 
> end code you are probably not passing the data through as you expected. 
> Instead of using .GET, use .GET.get to get your data. This will either 
> return the value you want, or none.


I looked up GET.get Django and found an SO post titled, “Django request.GET 
<https://stackoverflow.com/questions/3500859/django-request-get>” which has 
quite a few up votes. Based on that SO answer, In my views.py I changed the 
line (where I declare the number variable) from `number = 
request.GET['ccEntry']` to `number = request.GET.get['ccEntry', None]`  

That gives a different error (a type error this time): 
https://pastebin.com/L81LVtzi 

You also mentioned my front end. I had included the template in my original 
post. I have since refined it so it is more readable. Here is my improved 
home.html template:







  Search 



  





 

   Enter your fake Chuckee Cheese Neptune credit card number!

   

  Must be a 16 digit number. 

   

 



   Original Card Number:

   {{ number }}

   Redacted Card Number:

   {{ redacted_num }}

Did this work?   









Sam, you also suggested:

I think you have made the error of not passing your data to the get header 
> as you didn't explicitly write this on the form element. 


I did explicitly include my data in my form element as you can see in the 
above template.


Check the URL and log the get object in Django to make sure the data is 
> actually appearing in both.


The data is present as “ccEntry” in both home.html and in views.py.




On Thursday, March 7, 2019 at 10:42:25 AM UTC-5, Sam Taiwo wrote:
>
> I would be careful how you pass the data on get, somewhere in your front 
> end code you are probably not passing the data through as you expected. 
> Instead of using .GET, use .GET.get to get your data. This will either 
> return the value you want, or none. I think you have made the error of not 
> passing your data to the get header as you didn't explicitly write this on 
> the form element. Check the URL and log the get object in Django to make 
> sure the data is actually appearing in both.
>
> On Thu, Mar 7, 2019, 13:52 drone4four > 
> wrote:
>
>> Hello!
>>
>> I’m trying to run a basic Django app which redacts a 16 digit number 
>> entered by the user. I had a it running a few minutes ago. I’m not sure 
>> what I changed, but now I am getting a MultiValueDictKeyError. I’ve triple 
>> checked every variable. The only dictionary in my project is in views.py at 
>> line 7. As far as I can tell, it’s all accurate and positioned correctly. I 
>> don’t recall changing this dictionary or any other operator around this 
>> line. I’m stumped. What would you people suggest? Have a look at my setup.
>>
>>
>> *Here is the error and traceback in full:* https://pastebin.com/QwSrmAJx 
>>
>> Here is my urls.py:
>> from django.conf.urls import  include, url
>>
>>
>>
>> from django.contrib import admin
>>
>> from django.urls import path
>>
>> from . import views
>>
>>
>> urlpatterns = [
>>
>>url(r'^admin/', admin.site.urls),
>>
>>url(r'^$', views.home, name='home'),
>>
>>
>>
>> views.py:
>> from django.http import HttpResponse
>>
>>
>>
>> from django.shortcuts import render
>>
>>
>> def home(request):
>>
>>number = request.GET['ccEntry']
>>
>>redacted_num = '   {}'.format(number[-4:])
>>
>>return render(request, 'home.html', {'number':number, 'redacted_num':
>> redacted_num})
>>
>>
>>
>> home.html template:
>> 
>>
>>
>>
>>
>> 
>>
>> 
>>
>>  
>>
>>Enter your fake Chuckee Cheese Neptune credit card number!
>>
>>
>>
>>  
>>
>>  
>>
>>  
>>
>>Must be a 16 digit number.
>>
>>  
>>
>>  
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>Original Card Number:
>>
>>
>>
>>{{ number }}
>>
>>
>>
>>Redacted Card Number:
>>
>>
>>
>>{{ redacted_num }}
>>
>>
>>
>> Did this work?   
>>
>>
>>
>> 
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

Django credit card redaction app - - MultiValueDictKeyError

2019-03-07 Thread drone4four


Hello!

I’m trying to run a basic Django app which redacts a 16 digit number 
entered by the user. I had a it running a few minutes ago. I’m not sure 
what I changed, but now I am getting a MultiValueDictKeyError. I’ve triple 
checked every variable. The only dictionary in my project is in views.py at 
line 7. As far as I can tell, it’s all accurate and positioned correctly. I 
don’t recall changing this dictionary or any other operator around this 
line. I’m stumped. What would you people suggest? Have a look at my setup.


*Here is the error and traceback in full:* https://pastebin.com/QwSrmAJx 

Here is my urls.py:
from django.conf.urls import  include, url



from django.contrib import admin

from django.urls import path

from . import views


urlpatterns = [

   url(r'^admin/', admin.site.urls),

   url(r'^$', views.home, name='home'),



views.py:
from django.http import HttpResponse



from django.shortcuts import render


def home(request):

   number = request.GET['ccEntry']

   redacted_num = '   {}'.format(number[-4:])

   return render(request, 'home.html', {'number':number, 'redacted_num':
redacted_num})



home.html template:









 

   Enter your fake Chuckee Cheese Neptune credit card number!

   

 

 

 

   Must be a 16 digit number.

 

 

   

   

   

   

   Original Card Number:

   

   {{ number }}

   

   Redacted Card Number:

   

   {{ redacted_num }}

   

Did this work?   

   





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/49da3086-6f3d-415b-b451-7e4c6a6e542c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble deploying Django/wagtail on Ubuntu 14.04

2018-04-03 Thread drone4four


Thank you for your reply, Tom.


Here it is running as intended: https://daniel496.agency/


Inside the TEMPLATES variable, the line for ‘DIRS’ now a list which now 
reads: [PROJECT_ROOT + '/bakerydemo/templates']

'DIRS': [PROJECT_ROOT + '/bakerydemo/templates'],



M project root directory is /home/tranq/bakerydemo and the addition symbol 
binds the subsequent string together to create a new string as it is read 
by the interpreter: '/home//bakerydemo/bakerydemo/templates'

I also had to toy around a bit with group and ownership permissions.  Here 
are the winning commands I used in the end:

$ chmod 775 /home/tranq/bakerydemo
> $ chown :www-data /home/tranq/bakerydemo
> $ chmod 775 /home/tranq/bakerydemo/bakerydemodb
> $ chown :www-data /home/tranq/bakerydemo/bakerydemodb
> $ chown -R :www-data /home/tranq/bakerydemo/bakerydemo/media

 

I had this demo running perfectly weeks ago. I meant to report back here 
like this sooner. Sorry.  Better late than never?

Thanks again.

On Tuesday, March 20, 2018 at 2:49:59 PM UTC-4, Tom Evans wrote:
>
> It is not looking for "home_page.html", it is looking for 
> "base/home_page.html". On the error page it lists the locations it is 
> searching for the template, and explicitly says the directories that 
> are being searched. 
>
> You say the file is at 
> /home//bakerydemo/bakerydemo/templates/base/home_page.html 
>
> It says it is looking in /var/www/bakerydemo/templates/ 
>
> This means that your TEMPLATES['DIRS'] setting is wrong. 
>
> Looking at the configuration section of the error report shows that 
> you have put a relative path into TEMPLATE['DIRS']. Use 
> settings.PROJECT_ROOT to make that in to an absolute path, as the 
> example settings.py tells you to do. 
>
> Cheers 
>
> Tom 
>
> PS - there is very little point anonymising your username when you 
> share the full error report. 
>
> On Tue, Mar 20, 2018 at 4:14 PM, drone4four <drone...@gmail.com 
> > wrote: 
> > Thank you, Andreas.  I added the python-path to my Apache ssl.conf and 
> the 
> > Internal Server Error is gone now. It appears WSGI is serving my Django 
> > project perfectly. 
> > 
> > I adjusted ALLOWED_HOSTS just fine. But now Django is saying something 
> about 
> > "TemplateDoesNotExist at /" in base/home_page.html.  You can see the 
> full 
> > Django traceback here: https://daniel496.agency/ 
> > 
> > $ locate home_page.html 
> > 
> /home//.virtualenvs/wagtailbakerydemo/lib/python3.4/site-packages/wagtail/project_template/home/templates/home/home_page.html
>  
>
> > /home//bakerydemo/bakerydemo/templates/base/home_page.html 
> > 
> > The home_page.html file is present but apparently it is not being 
> referred 
> > to properly in my configuration.  Can anyone shed some light on what the 
> > issue could be now? 
> > 
> > Thanks. 
> > 
> > On Tuesday, March 20, 2018 at 5:45:27 AM UTC-4, Cictani wrote: 
> >> 
> >> You have to set the python-path too: 
> >> 
> >> WSGIDaemonProcess bakerydemo 
> >> python-home=/home//.virtualenvs/wagtailbakerydemo/ 
> >> python-path=/home//bakerydemo/ 
> >> 
> >> In the logs you see "No module named 'bakerydemo'" because you did not 
> add 
> >> the project directory to the python-path. Hope this works. 
> >> 
> >> Best regards 
> >> 
> >> Andreas 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/d90b8924-5458-4c0e-8f0f-2866af4dd156%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bafd5a65-c764-4d0e-a99e-908167bbad0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble deploying Django/wagtail on Ubuntu 14.04

2018-03-20 Thread drone4four
Thank you, Andreas.  I added the python-path to my Apache ssl.conf and the 
Internal Server Error is gone now. It appears WSGI is serving my Django 
project perfectly. 

I adjusted ALLOWED_HOSTS just fine. But now Django is saying something 
about "TemplateDoesNotExist at /" in base/home_page.html.  You can see the 
full Django traceback here: https://daniel496.agency/ 

$ locate home_page.html
/home//.virtualenvs/wagtailbakerydemo/lib/python3.4/site-packages/wagtail/project_template/home/templates/home/home_page.html
/home//bakerydemo/bakerydemo/templates/base/home_page.html

The home_page.html file is present but apparently it is not being referred 
to properly in my configuration.  Can anyone shed some light on what the 
issue could be now?

Thanks.

On Tuesday, March 20, 2018 at 5:45:27 AM UTC-4, Cictani wrote:
>
> You have to set the python-path too:
>
> WSGIDaemonProcess bakerydemo 
> python-home=/home//.virtualenvs/wagtailbakerydemo/ 
> python-path=/home//bakerydemo/
>
> In the logs you see "No module named 'bakerydemo'" because you did not add 
> the project directory to the python-path. Hope this works.
>
> Best regards
>
> Andreas
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d90b8924-5458-4c0e-8f0f-2866af4dd156%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trouble deploying Django/wagtail on Ubuntu 14.04

2018-03-19 Thread drone4four
I successfully installed wagtail ’s bakery demo site 
 locally.  I 
ended up leveraging the README for this bakery demo site 
 on their GitHub page which calls to 
use a ‘virtualenvwrapper 
’ instead of a 
typical venv.  As instructed I played around with some configuration files. 
I got it working. Here is a .webm video 
 showcasing my site 
running locally.  

But when I attempt to deploy it on my DigitalOcean Droplet, Apache is 
throwing all sorts of errors.  The problem is with my configuration. I am 
not sure what I have to change to make it right. 

Here is my site showing an Apache Internal Server 
Error: https://daniel496.agency/ 

Here  are the most recent lines of traceback 
from my Apache log file. That log file is pointing me in a few directions. 
I ensure that my Apache sites-available file points to wsgi.py inside the 
bakerydemo project folder.  I tried both wsgi.py and production_wsgi.py.

Here are the contents of my ssl Apache sites-available ssl config:




ServerAdmin @gmail.com
ServerName daniel496.agency
ServerAlias www.daniel496.agency
#   DocumentRoot /var/www/html/daniel496.agency/public_html


#   ErrorLog ${APACHE_LOG_DIR}/error.log
ErrorLog ${APACHE_LOG_DIR}/daniel496/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


# Original Django project commented out 19 March 2018 to make room 
for Django project below

Alias /static /home//TheGreatWork/static
/TheGreatWork/static>
Require all granted



/TheGreatWork/TheGreatWork>

Require all granted




WSGIDaemonProcess TheGreatWork python-home=/home/
/TheGreatWork/venv
WSGIProcessGroup TheGreatWork
WSGIScriptAlias / /home//TheGreatWork/TheGreatWork/wsgi.py







# 2nd Django project (wagtail demo)
Alias /static /home//bakerydemo/bakerydemo/static
/bakerydemo/bakerydemo/static>
Require all granted



/bakerydemo/bakerydemo>

Require all granted




WSGIDaemonProcess bakerydemo python-home=/home/
/.virtualenvs/wagtailbakerydemo/
WSGIProcessGroup bakerydemo
WSGIScriptAlias / /home//bakerydemo/bakerydemo/wsgi.py


Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/daniel496.agency/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/daniel496.agency/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/daniel496.agency/chain.pem






Take note the project called, TheGreatWork.  That is a previous project 
I've temporarily set aside.  I invoked a multi-line block comment in this 
Apache starting with  and ending with 


As part of setting up virtualenvwrapper, I’ve assigned my virtual 
environments to: /home//.virtualenvs, which appears to be an issue in 
the error log as well, so maybe this could be the problem with my setup?

I’ve ruled out the possibility that the issue has something to do with the 
Python version 2.7-based libapache2-mod-wsgi because I purged my system of 
that library. All that exists now is libapache2-mod-wsgi-py3.

I'm running Ubuntu 14.04 on my Droplet, running Python 3.4 and Django 2.0.

Is there any other information I could provide to help troubleshoot?

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4a00eab7-7378-4ce3-808f-c3e6a810a4f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trouble deploying Django (project folder, wsgi.py and libapache2-mod-wsgi)

2018-03-08 Thread drone4four


I’m having some issues deploying Django.


Here is my site: https://daniel496.agency/ 


I’m running a Digital Ocean Droplet with Ubuntu 14.04 and Python v3.4 with 
Django 2.0.2 installed.


In this post first I share what errors I am encountering, then what I think 
is the issue is and then what I’ve tried to resolve the issue.  At the end 
of this post are my configuration files like ssl.conf and wsgi.py.


Before I begin, I think the issue might involve the naming of my project 
folders. My project folder on my local machine is named: 
`first_project_attempt`.  But on my remote server, the project folder is 
named, `cel2fah`. I copied the contents locally to my remote host and now 
trying to iron out the issues.


Here I go.  If you access my site linked to above, right now it is showing:


Internal Server Error
> The server encountered an internal error or misconfiguration and was 
> unable to complete your request.
> Please contact the server administrator at @gmail.com to inform them 
> of the time this error occurred, and the actions you performed just before 
> this error.
> More information about this error may be available in the server error log.
> Apache/2.4.7 (Ubuntu) Server at daniel496.agency Port 443


Here are the last ~50 lines of my apache error log file: 
https://pastebin.com/UPsTmf28 


I’m thinking that there could be a potential conflict between 
libapache2-mod-wsgi and libapache2-mod-wsgi-py3.  I encountered a similar 
issue a few weeks ago. There are apparently still traces of 
libapache2-mod-wsgi (for Python 2.7) still flagged as active on my system 
given that $ sudo dpkg -s libapache2-mod-wsgi prints:


Package: libapache2-mod-wsgi
> Status: deinstall ok config-files
> Priority: optional
> Section: httpd
> Installed-Size: 242
> Maintainer: Ubuntu Developers 
> Architecture: amd64
> Source: mod-wsgi
> Version: 3.4-4ubuntu2.1.14.04.2
> Config-Version: 3.4-4ubuntu2.1.14.04.2
> Provides: httpd-wsgi
> Depends: libc6 (>= 2.14), libpython2.7 (>= 2.7), apache2-api-20120211, 
> python (>= 2.7), python (<< 2.8)
> Conffiles:
> /etc/apache2/mods-available/wsgi.load 06d2b4d2c95b28720f324bd650b7cbd6 
> obsolete
> /etc/apache2/mods-available/wsgi.conf c4ca5be35d0820b5d5cc2892097b476b 
> obsolete
> Description: Python WSGI adapter module for Apache
> The mod_wsgi adapter is an Apache module that provides a WSGI (Web Server
> Gateway Interface, a standard interface between web server software and
> web applications written in Python) compliant interface for hosting Python
> based web applications within Apache. The adapter provides significantly
> better performance than using existing WSGI adapters for mod_python or CGI.
> .
> This package provides module for Python 2.X.
> Homepage: http://www.modwsgi.org/
> Original-Maintainer: Debian Python Modules Team 
> 


However when I go to remove it, it says it’s not installed:


$ sudo apt remove libapache2-mod-wsgi
> Reading package lists... Done
> Building dependency tree   
> Reading state information... Done
> Package 'libapache2-mod-wsgi' is not installed, so not removed
> 0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.


More to the point, when invoking this as root:


apache2ctl -t -D DUMP_MODULES


...it lists what modules apache2 has loaded. And libapache2-mod-wsgi (for 
Python version 2) is included.  So I Google ‘how to remove apache modules’ 
which turns up this SO post: 
https://stackoverflow.com/questions/9288865/how-can-i-uninstall-an-apache2-module

So I set out to rename my libapache2-mod-wsgi.so (for Python version 2) 
from my apache2 modules directory inside /usr/lib. I see a symlink 
mod_wsgi.so which refers to mod_wsgi.so-3.4:


@:/usr/lib/apache2/modules$ ls -la mod_wsgi*
> lrwxrwxrwx 1 root root 15 Nov 18 2014 mod_wsgi.so -> mod_wsgi.so-3.4
> -rw-r--r-- 1 root root 174448 Nov 18  2014 mod_wsgi.so-3.4
> @:/usr/lib/apache2/modules$ 


So is my Apache serving the libapache2-mod-wsgi module for python2 or just 
for python3 or what?


What else can you people determine could be the issue here?


Here is my wsgi.py:

> """
> WSGI config for first_project_attempt project.
> It exposes the WSGI callable as a module-level variable named 
> ``application``.
> For more information on this file, see
> https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
> """
> import os
> import sys
> from django.core.wsgi import get_wsgi_application
> sys.path.append('/home/tranq/cel2fah/cel2fah')
> # NEW:
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cel2fah.settings")
> # OLD:
> # os.environ.setdefault("DJANGO_SETTINGS_MODULE", 
> "first_project_attempt.settings")


application = get_wsgi_application()

And my ssl.conf:



>
> 
>ServerAdmin @gmail.com
>ServerName daniel496.agency
>ServerAlias www.daniel496.agency
> #   DocumentRoot /var/www/html/daniel496.agency/public_html
> #   ErrorLog 

Re: Question about dot notation syntax (Django source)

2018-02-23 Thread drone4four


Hi Andreas!

Thank you for your reply.

You said:


The dot notation (as you call it) references a class that you can find if 
> you look in the django package, under folder contrib, folder auth, file 
> password_validation.py you will find a class class 
> UserAttributeSimilarityValidator. See the "dots" as directories / files 
> (they are modules).


So when a Django script (settings.py for example) is called and the 
libraries are imported at the top of the script (or in my example above, 
when the `AUTH_PASSWORD_VALIDATORS` variable is declared) it looks inside 
`site-packages` (inside my virtual environment) for the `django` directory, 
then for the `auth` directory which contains the `password_validation.py` 
module. settings.py refers to four classes inside the password_validation 
script:

   - 
   
   UserAttributeSimilarityValidator
   - 
   
   MinimumLengthValidator
   - 
   
   CommonPasswordValidaor
   - 
   
   NumericPasswordValidator
   

Therefore, and more to your point, Andreas: The 
`django.contrib.auth.password_validation.UserAttributeSimilarityValidator` 
pattern here translated into pseudocode might reflect this: 
`DjangoDirectory.ContribDirectory.AuthDirectory.ThisModule.ThisClass`. 

This structure applies also when a programmer imports his or her functions 
at the top of any Python script.  To distinguish references to directories, 
modules, and classes in an import statement, the programmer just has to 
know their filesystem and their code, right?

Andreas: I meant to follow up here sooner.  Sorry for the delay.  Here it 
is.  


On Friday, February 16, 2018 at 3:35:34 AM UTC-5, Andréas Kühne wrote:
>
> Like Juan says,
>
> Read the documentation for modules and dictionaries and I think you will 
> be better off. However, here is a quick rundown of your questions:
>
> AUTH_PASSWORD_VALIDATORS = [
> {
> 'NAME': 
> 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
> ,
> },
>
> {
> 'NAME': 
> 'django.contrib.auth.password_validation.MinimumLengthValidator',
> },
>
> {
> 'NAME': 
> 'django.contrib.auth.password_validation.CommonPasswordValidator',
> },
>
> {
> 'NAME': 
> 'django.contrib.auth.password_validation.NumericPasswordValidator',
> },
> ]
>
>
>
> 1. The first item in the list is the first dictionary that is present. A 
> dictionary in Python starts with a { and ends with a }. So the first item 
> is:
> {
> 'NAME': 
> 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
> ,
> },
>
> The AUTH_PASSWORD_VALIDATORS is a list of dictionaries with only one key 
> ("NAME") and one item in them. So this is the first item and therefore the 
> first validator in this case.
>
> 2. Your assumption on dictionaries is wrong because "NAME" is not the 
> dictionary, but rather a KEY IN a dictionary (the entire first dictionary 
> is under bullet point 1 here).
>
> 3. The dot notation (as you call it) references a class that you can find 
> if you look in the django package, under folder contrib, folder auth, file 
> password_validation.py you will find a class class 
> UserAttributeSimilarityValidator. See the "dots" as directories / files 
> (they are modules). 
>
> So there is really not that much to explain here - it is probably simpler 
> than you expect it to be :-)
>
> Regards,
>
> Andréas
>
> 2018-02-16 5:09 GMT+01:00 Juan Pablo Romero Bernal <jromer...@gmail.com 
> >:
>
>> Hi, 
>>
>> You must read: https://docs.python.org/3/tutorial/modules.html
>>
>> and
>>
>> https://docs.python.org/3/tutorial/datastructures.html#dictionaries
>>
>> Cheers, 
>>
>>
>> On Thu, Feb 15, 2018 at 8:06 PM, drone4four <drone...@gmail.com 
>> > wrote:
>>
>>> In, “Password management in Django 
>>> <https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#how-django-stores-passwords>”,
>>>  
>>> it explains that this particular doc is for advanced users, like Django 
>>> admins who need to choose different hashing algorithms.  So it’s not really 
>>> necessary for a beginner user like me to understand.  From the doc:
>>>
>>> ...depending on your requirements, you may choose a different algorithm, 
>>>> or even use a custom algorithm to match your specific security situation. 
>>>> Again, most users shouldn’t need to do this – if you’re not sure, you 
>>>> probably don’t. If you do, please read on...
>>>
>>>
>>> I don’t. So I don’t need to conti

Question about dot notation syntax (Django source)

2018-02-15 Thread drone4four


In, “Password management in Django 
”,
 
it explains that this particular doc is for advanced users, like Django 
admins who need to choose different hashing algorithms.  So it’s not really 
necessary for a beginner user like me to understand.  From the doc:

...depending on your requirements, you may choose a different algorithm, or 
> even use a custom algorithm to match your specific security situation. 
> Again, most users shouldn’t need to do this – if you’re not sure, you 
> probably don’t. If you do, please read on...


I don’t. So I don’t need to continue reading. 

But I do have some questions about dot notation in general as some code 
appears in settings.py. Lines 87 - 100 in this file appear as follows:

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},

{
'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
},

{
'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
},

{
'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]



Can someone please identify the first item in this list?  I understand that 
all the items in this list are dictionaries.  The first dictionary is 
named, ‘NAME’.  The key involves libraries, functions, variables, class 
names and more functions.  Which is which? Is `django` the library? What is 
`contrib`? Is this a function name or a class name?  If `contrib` is a 
function name or class name, where is it located in my venv or Django 
project folder? 

What does each word in the dictionary mean or refer to?  Can some one 
please explain the syntax?

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e285f69d-3aad-4d99-b46e-7f6be5ccbffb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to deploy Django 2.0.2 (DigitalOcean)

2018-02-07 Thread drone4four
Yes I know, *sacrac*. My venv was configured with Python 3.4 and pip3 
pulled Django 2.0.1 beautifully from the start.

I resolved my issue. The problem was with my Apache mod_wsgi version was 
with python 2.  I found and installed libapache2-mod-wsgi-py3. Now my site 
runs perfectly.

On Wednesday, February 7, 2018 at 10:31:02 PM UTC-5, sacrac wrote:
>
> i think you install with python 3 right, django 2.0.x run only version 
> python3!!
>
> On Wed, Feb 7, 2018 at 9:13 PM, drone4four <drone...@gmail.com 
> > wrote:
>
>> I am struggling deploying Django 2.0.2 on my DigitalOcean Droplet (Ubuntu 
>> 14.04) with Apache mod_wsgi.
>>
>> I’ve followed this guide 
>> <https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04>
>>  
>> closely. That guide focuses on setting up Django for delivery through 
>> port 80 (http).  I’m trying to establish a port 443 connection (https) and 
>> ssl so I am using this guide 
>> <https://stackoverflow.com/questions/32812570/configure-ssl-certificate-on-apache-for-django-application-mod-wsgi>
>> .
>>
>> When I navigate to my site, www.daniel496.agency , it basically times 
>> out after a minute or two and resolves to this error message:
>>
>> Internal Server Error
>>> The server encountered an internal error or misconfiguration and was 
>>> unable to complete your request.
>>> Please contact the server administrator at coffee.dri...@gmail.com 
>>>  to inform them of the time this error occurred, and the 
>>> actions you performed just before this error.
>>> More information about this error may be available in the server error 
>>> log.
>>> --
>>> Apache/2.4.7 (Ubuntu) Server at www.daniel496.agency Port 443
>>
>>
>> The strangest red flag I am aware of at this point is the contents of 
>> /var/log/apache2/errors.log . Here are the first ten lines of this log 
>> file:
>>
>>
>> 1 [Mon Feb 05 06:25:13.210967 2018] [ssl:warn] [pid 27373] AH01909: 
>>> RSA certificate configured for 127.0.0.1:443 does NOT include an ID 
>>> which matches the server name
>>> 2 [Mon Feb 05 06:25:13.213123 2018] [ssl:warn] [pid 27373] AH02292: 
>>> Init: Name-based SSL virtual hosts only work for clients with TLS server 
>>> name indication support (RFC 4366)
>>> 3 [Mon Feb 05 06:25:13.214637 2018] [mpm_prefork:notice] [pid 27373] 
>>> AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.22 OpenSSL/1.0.1f 
>>> mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
>>> 4 [Mon Feb 05 06:25:13.214675 2018] [core:notice] [pid 27373] 
>>> AH00094: Command line: '/usr/sbin/apache2'
>>> 5 ImportError: No module named site
>>> 6 ImportError: No module named site
>>> 7 ImportError: No module named site
>>> 8 ImportError: No module named site
>>> 9 ImportError: No module named site
>>>   10 ImportError: No module named site
>>
>>
>> Lines 5-10 repeat 355,822 times
>>
>> Here is my vhost config file, 
>> /etc/apache2/sites-available/daniel496.agency-le-ssl.conf:
>>
>>
>>   ServerAdmin 
>>> coffee.dri...@gmail.com  ServerName daniel496.agency 
>>> ServerAlias www.daniel496.agency DocumentRoot 
>>> /var/www/html/daniel496.agency/public_html ErrorLog 
>>> ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 
>>> # Django project Alias /static /home/tranq/cel2fah/static >> /home/tranq/cel2fah/static> Require all granted  >> /home/tranq/cel2fah/cel2fah>  Require all granted  
>>>  WSGIDaemonProcess cel2fah2 python-path=/home/tranq/cel2fah 
>>> python-home=/home/tranq/cel2fah/venv WSGIProcessGroup cel2fah2 
>>> WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py Include 
>>> /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile 
>>> /etc/letsencrypt/live/daniel496.agency/cert.pem SSLCertificateKeyFile 
>>> /etc/letsencrypt/live/daniel496.agency/privkey.pem SSLCertificateChainFile 
>>> /etc/letsencrypt/live/daniel496.agency/chain.pem   
>>
>>
>>
>> Is there any other information I can provide?
>>
>> Thanks for your attention.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, 

Trying to deploy Django 2.0.2 (DigitalOcean)

2018-02-07 Thread drone4four


I am struggling deploying Django 2.0.2 on my DigitalOcean Droplet (Ubuntu 
14.04) with Apache mod_wsgi.

I’ve followed this guide 

 
closely. That guide focuses on setting up Django for delivery through port 
80 (http).  I’m trying to establish a port 443 connection (https) and ssl 
so I am using this guide 

.

When I navigate to my site, www.daniel496.agency , it basically times out 
after a minute or two and resolves to this error message:

Internal Server Error
> The server encountered an internal error or misconfiguration and was 
> unable to complete your request.
> Please contact the server administrator at coffee.drinker.dan...@gmail.com 
> to inform them of the time this error occurred, and the actions you 
> performed just before this error.
> More information about this error may be available in the server error log.
> --
> Apache/2.4.7 (Ubuntu) Server at www.daniel496.agency Port 443


The strangest red flag I am aware of at this point is the contents of 
/var/log/apache2/errors.log . Here are the first ten lines of this log file:


1 [Mon Feb 05 06:25:13.210967 2018] [ssl:warn] [pid 27373] AH01909: RSA 
> certificate configured for 127.0.0.1:443 does NOT include an ID which 
> matches the server name
> 2 [Mon Feb 05 06:25:13.213123 2018] [ssl:warn] [pid 27373] AH02292: 
> Init: Name-based SSL virtual hosts only work for clients with TLS server 
> name indication support (RFC 4366)
> 3 [Mon Feb 05 06:25:13.214637 2018] [mpm_prefork:notice] [pid 27373] 
> AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.22 OpenSSL/1.0.1f 
> mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
> 4 [Mon Feb 05 06:25:13.214675 2018] [core:notice] [pid 27373] AH00094: 
> Command line: '/usr/sbin/apache2'
> 5 ImportError: No module named site
> 6 ImportError: No module named site
> 7 ImportError: No module named site
> 8 ImportError: No module named site
> 9 ImportError: No module named site
>   10 ImportError: No module named site


Lines 5-10 repeat 355,822 times

Here is my vhost config file, 
/etc/apache2/sites-available/daniel496.agency-le-ssl.conf:


  ServerAdmin 
> coffee.drinker.dan...@gmail.com ServerName daniel496.agency ServerAlias 
> www.daniel496.agency DocumentRoot 
> /var/www/html/daniel496.agency/public_html ErrorLog 
> ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 
> # Django project Alias /static /home/tranq/cel2fah/static  /home/tranq/cel2fah/static> Require all granted   /home/tranq/cel2fah/cel2fah>  Require all granted  
>  WSGIDaemonProcess cel2fah2 python-path=/home/tranq/cel2fah 
> python-home=/home/tranq/cel2fah/venv WSGIProcessGroup cel2fah2 
> WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py Include 
> /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile 
> /etc/letsencrypt/live/daniel496.agency/cert.pem SSLCertificateKeyFile 
> /etc/letsencrypt/live/daniel496.agency/privkey.pem SSLCertificateChainFile 
> /etc/letsencrypt/live/daniel496.agency/chain.pem   



Is there any other information I can provide?

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d10625a1-f380-4ab2-8ec0-efa25aaea5b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-26 Thread drone4four


The username on my droplet is ‘tranq’ but there is a line in both my vhost 
config files which reads:



So I swapped out ‘user’ for ‘tranq’. That line now reads:



Now some of my static files are accessible.  For example you can see here:

https://www.angeles4four.info/static/admin/css/responsive.css

https://www.angeles4four.info/static/admin/css/login.css

But the following is still saying, “Forbidden”: 

https://www.angeles4four.info/static/admin/ 

This may be pointing to an issue I noticed with how my user and group 
permissions are set up for Django.  The sqlite.db file was grouped in with 
‘tranq’. According to the guide I’ve been using, it should be: ‘www-data’. 
 I’m not sure how I overlooked this mistake because I very clearly remember 
doing it properly.  I think I’m conflating this with one of my multiple 
recent previous attempts following this guide. Anyways, here is what my 
group permissions look like now from within my project directory:

$ ls -la

total 68

drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 .

drwxr-xr-x 18 tranq tranq 4096 Jan 26 21:57 ..

drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:13 cel2fah

-rw-rw-r--  1 tranq www-data 38912 Jan 25 23:11 db.sqlite3

-rwxrwxr-x  1 tranq tranq  539 Jan 25 23:05 manage.py

drwxrwxr-x  3 tranq tranq 4096 Jan 25 23:12 static

drwxrwxr-x  5 tranq tranq 4096 Jan 25 23:04 venv

Notice sqlite.db above? It now says ‘www-data’.  This is how it should be, 
right?

The parent directory (home user folder) shows these permissions for my 
project:

...

drwxrwxr-x  5 tranq www-data  4096 Jan 25 23:12 cel2fah

Does this look right to all of you?

The steps I took to arrange the permissions as such were from the bottom of 
the mod_wsgi guide on DigitalOcean 
<https://www.google.ca/url?sa=t=j==s=web=3=0ahUKEwjJ_d_P0OfYAhVlxoMKHZlBBkEQFgg0MAI=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04=AOvVaw2wt2StyReKq9zmPyQnkrO7>
 
which I referred to initially.

Thanks for your attention.

On Friday, January 26, 2018 at 1:21:07 AM UTC-5, drone4four wrote:
>
> You’re right, @Antonis, that I don’t want my Django source code exposed. 
> No sysadmin would.  I have since moved my Django project folder to my home 
> user’s directory. However (out of curiosity), if I continued to house 
> Django in my public_html folder (which I am not any more, but say if i did) 
> I would think that my .htaccess config file would prevent unauthorized 
> access to my Django source.  Am I right?
>
> I didn’t realize that Django was suppose to be run using wsgi.  I was just 
> foolishly running the server with ``$ python manage.py runserver 
> 0.0.0.0:8000`` like when I was testing locally when I was coding my app. 
> The keyword here is mod_wsgi.  So I found this guide 
> <https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04>.
>  
> I followed along but the issue I now have is that Apache serves my 
> public_html folder (just some light  HTML, CSS and Js).  Serving these 
> contents take priority over Django.  I’m OK with this. I would prefer to 
> keep my public_html folder accessible as it is, but how do I arrange for 
> wsgi to serve Django from a subdirectory, say: 
> www.angeles4four.info/cel2fah or something like that? 
>
> @Mulianto:
>
> An example of a static file would be a style sheet, like: 
> ~/cel2fah/static/admin/css/responsive.css
>
> How would trying to access this CSS file help?
>
> I tried: 
>
> http://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css 
>
> https://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css 
> <http://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css> 
>
> Both show “This site can’t be reached”
>
> Here are the contents of my two apache configuration files.
>
> /etc/apache2/sites-available/angeles4four.info.conf :
>
> 
>
>
>
> ServerAdmin coffee.drinker.dan...@gmail.com
>
> ServerName angeles4four.info
>
> ServerAlias www.angeles4four.info
>
> DocumentRoot /var/www/html/angeles4four.info/public_html
>
>
> 
>
> Options Indexes FollowSymlinks
>
> AllowOverride All
>
> Require all granted
>
> 
>
>
> ErrorLog ${APACHE_LOG_DIR}/error.log
>
> CustomLog ${APACHE_LOG_DIR}/access.log combined
>
>
> RewriteEngine on
>
> RewriteCond %{SERVER_NAME} =angeles4four.info [OR]
>
> RewriteCond %{SERVER_NAME} =www.angeles4four.info
>
> RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} 
> [END,NE,R=permanent]
>
>
> Alias /static /home/t

Re: Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-25 Thread drone4four


You’re right, @Antonis, that I don’t want my Django source code exposed. No 
sysadmin would.  I have since moved my Django project folder to my home 
user’s directory. However (out of curiosity), if I continued to house 
Django in my public_html folder (which I am not any more, but say if i did) 
I would think that my .htaccess config file would prevent unauthorized 
access to my Django source.  Am I right?

I didn’t realize that Django was suppose to be run using wsgi.  I was just 
foolishly running the server with ``$ python manage.py runserver 
0.0.0.0:8000`` like when I was testing locally when I was coding my app. 
The keyword here is mod_wsgi.  So I found this guide 
<https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04>.
 
I followed along but the issue I now have is that Apache serves my 
public_html folder (just some light  HTML, CSS and Js).  Serving these 
contents take priority over Django.  I’m OK with this. I would prefer to 
keep my public_html folder accessible as it is, but how do I arrange for 
wsgi to serve Django from a subdirectory, say: www.angeles4four.info/cel2fah 
or something like that? 

@Mulianto:

An example of a static file would be a style sheet, like: 
~/cel2fah/static/admin/css/responsive.css

How would trying to access this CSS file help?

I tried: 

http://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css 

https://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css 
<http://www.angeles4four.info:8000/cel2fah/static/admin/css/responsive.css> 

Both show “This site can’t be reached”

Here are the contents of my two apache configuration files.

/etc/apache2/sites-available/angeles4four.info.conf :





ServerAdmin coffee.drinker.dan...@gmail.com

ServerName angeles4four.info

ServerAlias www.angeles4four.info

DocumentRoot /var/www/html/angeles4four.info/public_html




Options Indexes FollowSymlinks

AllowOverride All

Require all granted




ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined


RewriteEngine on

RewriteCond %{SERVER_NAME} =angeles4four.info [OR]

RewriteCond %{SERVER_NAME} =www.angeles4four.info

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} 
[END,NE,R=permanent]


Alias /static /home/tranq/cel2fah/static




Require all granted








Require all granted






WSGIDaemonProcess cel2fah python-path=/home/tranq/cel2fah 
python-home=/home/tranq/cel2fah/venv

WSGIProcessGroup cel2fah

WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py






And /etc/apache2/sites-available/angeles4four.info.conf :







ServerAdmin coffee.drinker.dan...@gmail.com

ServerName angeles4four.info

ServerAlias www.angeles4four.info

DocumentRoot /var/www/html/angeles4four.info/public_html



ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined


Alias /static /home/tranq/cel2fah/static




Require all granted








Require all granted






# WSGIDaemonProcess cel2fah python-path=/home/tranq/cel2fah 
python-home=/home/tranq/cel2fah/venv

# WSGIProcessGroup cel2fah

# WSGIScriptAlias / /home/tranq/cel2fah/cel2fah/wsgi.py


SSLCertificateFile /etc/letsencrypt/live/angeles4four.info/cert.pem

SSLCertificateKeyFile 
/etc/letsencrypt/live/angeles4four.info/privkey.pem

Include /etc/letsencrypt/options-ssl-apache.conf

SSLCertificateChainFile 
/etc/letsencrypt/live/angeles4four.info/chain.pem







Thanks to you both for your help so far.

On Saturday, January 20, 2018 at 10:00:57 PM UTC-5, drone4four wrote:
>
> I’ve played with a little Django (v2.0.1) locally. Now I am trying to 
> implement a test case on my production Apache web server. I’m running an 
> Ubuntu 14.04 DigitalOcean droplet (will upgrade to 18.04 later this year).
>
> I got Django running.
>
> Here it is: http://www.angeles4four.info:8000/
>
> Before I log into my admin panel, I figure it’s best practices to set up 
> HTTPS first. But when I visit that URL, Chrome throws this message:
>
>
> This site can’t provide a secure connection http://www.angeles4four.info 
>> sent an invalid response. ERR_SSL_PROTOCOL_ERROR
>
>
> And my shell on my server shows this message:
>
> [20/Jan/2018 23:54:39] "GET / HTTP/1.1" 200 16559 [21/Jan/2018 00:01:23] 
>> code 400, message Bad request syntax 
>> ('\x16\x03\x01\x00Ì\x01\x00\x00È\x03\x03&6U\x10µ\x82\x97\x7f´8\x1e«\x0e¿ÿ§\x89æ\x82

Deploying SSL for my Django 2.0.1 server with Apache on Ubuntu 16.04 (droplet)

2018-01-20 Thread drone4four
I’ve played with a little Django (v2.0.1) locally. Now I am trying to 
implement a test case on my production Apache web server. I’m running an 
Ubuntu 14.04 DigitalOcean droplet (will upgrade to 18.04 later this year).

I got Django running.

Here it is: http://www.angeles4four.info:8000/

Before I log into my admin panel, I figure it’s best practices to set up 
HTTPS first. But when I visit that URL, Chrome throws this message:


This site can’t provide a secure connection http://www.angeles4four.info 
> sent an invalid response. ERR_SSL_PROTOCOL_ERROR


And my shell on my server shows this message:

[20/Jan/2018 23:54:39] "GET / HTTP/1.1" 200 16559 [21/Jan/2018 00:01:23] 
> code 400, message Bad request syntax 
> ('\x16\x03\x01\x00Ì\x01\x00\x00È\x03\x03&6U\x10µ\x82\x97\x7f´8\x1e«\x0e¿ÿ§\x89æ\x82\r¢G§\x01ç°P%\x80)ÕÃ\x00\x00\x1c
>  
> * À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00') [21/Jan/2018 
> 00:01:23] *You're accessing the development server over HTTPS, but it 
> only supports HTTP.*


That’s because SSL isn’t set up. My current SSL Certificate Authority is 
Let’s Encrypt. SSL is running properly for my public_html content but not 
for my recent deployment of Django.

I found some resources elsewhere on SO for setting up SSL with Django.

In an SO post titled, “Configure SSL Certificate on Apache for Django 
Application (mod_wsgi)”, a highly upvoted answer by Alexey Kuleshevich 
suggests a template for 000-default.conf and default-ssl.conf for Apache 
vhosts. See here: Configure SSL Certificate on Apache for Django 
Application (mod_wsgi) 


I did my best to change up the suggested values and entries so that they 
refer to my specific configuration. Here are what these two vhost 
configuration files of mine look like now.

/etc/apache2/sites-available/angeles4four.info-le-ssl.conf:

 

#ServerName http://www.example.com
ServerAdmin coffee.drinker.dan...@gmail.com
ServerName angeles4four.info
ServerAlias http://www.angeles4four.info
DocumentRoot /var/www/html/angeles4four.info/public_html


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


# Django Application
Alias /static /var/www/html/angeles4four.info/public_html/Cel2FahConversion

Require all granted



Require all granted


WGIDaemonProcess cel 
python-path=/var/www/html/angeles4four.info/public_html/Cel2FahConversion/venv/bin/python3
WSGIProcessGroup cel
WSGIScriptAlias / 
/var/www/html/angeles4four.info/public_html/Cel2FahConversion/Cel2FahConversion/Cel2FahConversion/wsgi.py


SSLCertificateFile /etc/letsencrypt/live/angeles4four.info/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/angeles4four.info/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/angeles4four.info/chain.pem




angeles4four.info.conf:

Quote:



#ServerName http://www.example.com
ServerAdmin coffee.drinker.dan...@gmail.com
ServerName angeles4four.info
ServerAlias http://www.angeles4four.info
DocumentRoot /var/www/html/angeles4four.info/public_html

Options Indexes FollowSymlinks
AllowOverride All
Require all granted



ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


RewriteEngine on
RewriteCond %{SERVER_NAME} =angeles4four.info [OR]
RewriteCond %{SERVER_NAME} =www.angeles4four.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]


No dice. I still get the same traceback as I initially shared.

The next SO post I came across suggests modifying settings.py. Here it is: 
Error 
"You're accessing the development server over HTTPS, but it only supports 
HTTP" 


The upvoted suggestion here by YoYo is to modify session cookies and secure 
SSL redirect. YoYo also recommends managing base, local, production 
settings which doesn’t really apply to me. So I tried adding these three 
lines to my settings.py:


SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True


My python3 manage.py runserver shell traceback still says: *“You're 
accessing the development server over HTTPS, but it only supports HTTP.”*

Any ideas? What else could I try?

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c0592c57-9a5a-4693-b685-80933643eb49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django field model for HTML parser?

2017-12-14 Thread drone4four
Thank you Mike for the help. I'll look into bleaching my HTML.  Great doc.

So it's easy but not recommended to enable all HTML.  I've got alotta 
custom legacy  code with dividers and elements with classes and such which 
I intend on trying to port over into Django.  Would enabling these aspects 
to me HTML pose as a security risk?  

More about the security: I know JavaScript can be prone to errors and 
security risks, but HTML?  Hypothetically speaking, how might allowing all 
HTML by bleaching my code with this plugin be risky?

On Thursday, December 14, 2017 at 12:26:37 AM UTC-5, Mike Dewhirst wrote:
>
> On 14/12/2017 4:00 PM, drone4four wrote: 
> > Hi fellow Djangoistas: 
> > 
> > I'm back. 
> > 
> > Thank you Atonis for your help.  I suppose I can leave the WYSIWYG 
> > editor static files for later when I have alittle more experience.  
> > For now though: how can I enable HTML markup to parse like it should?  
> > The box where users on my Django website make a blog post, they can 
> > attach images, apply a timestamp but the content is just plain text.  
> > How do I make it so that when I user for example enters this: 
> > 
> > | 
> > Lorem Ipsum 
> > Hello and welcome to my first blog post 
> > | 
> > 
> > ...that it posts and parses not as plain text but with the heading 
> > showing with a slightly larger font size than the rest and the first 
> > sentence is bolded? 
>
> That is easy but dangerous. You need to permit only a subset of markup. 
> In your views you need to bleach [1] the user entered data then 
> mark_safe() it. Bleach has a default set of html tags probably including 
>  and  but you can add others. For all other tags it will 
> convert angle brackets into  and  thus disabling them. Django's 
> mark_safe will deliver any real tags to the browser. 
>
> [1] https://pypi.python.org/pypi/bleach 
>
>
>
> > 
> > Thanks again. 
> > 
> > -Drone4four 
> > 
> > On Sunday, November 19, 2017 at 5:31:37 AM UTC-5, Antonis Christofides 
> > wrote: 
> > 
> > Hello, 
> > 
> > First of all: If you are just starting to learn, and because the 
> > amount you have to learn can be overwhelming, I'd suggest to not 
> > care about the wysiwyg editor at this stage. Pretend that your 
> > users can enter HTML in the field, and do all the rest. After you 
> > get some understanding of static files, only then come back to 
> > this issue. 
> > 
> > But to (prematurely) answer your question, if you have DEBUG=True 
> > and running django with manage.py runserver, you shouldn't need to 
> > care about STATIC_ROOT and STATIC_URL and collectstatic. Just 
> > forget about them. When the time comes to deploy your application 
> > and turn DEBUG off, then you will need to understand how static 
> > files work in production 
> > <
> https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/>.
>  
>
> > 
> > Regards, 
> > 
> > Antonis 
> > 
> > Antonis Christofides 
> > http://djangodeployment.com 
> > 
> > 
> > On 2017-11-19 01:38, drone4four wrote: 
> >> 
> >> The official Django docs specify that STATIC_ROOT is indicated in 
> >> settings.py at the STATIC_URL variable (which is near the 
> >> bottom).  The official Django docs says: 
> >> 
> >> Configure your web server to serve the files in STATIC_ROOT 
> >> <
> https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_ROOT>under
>  
>
> >> the URL STATIC_URL 
> >> <
> https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_URL>. 
>
> >> 
> >> 
> >> (link 
> >> <
> https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/>) 
> >> 
> >> 
> >> I’m not running Apache. My Django serving is running locally. The 
> >> absolute path in my file tree to my Django root directory is: 
> >> 
> >> 
> /home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/
>  
>
> >> 
> >> Inside dobbs_portal_blog is where I placed the static folder. 
> >> Therefore, the line in my settings.py where I declare the 
> >> variable, I changed from the default: 
> >> 
> >> | 
> >> *STATIC_URL ='/static/'* 
> >> | 
> >> 
> >> to: 
> >> 
> >>

Re: Django field model for HTML parser?

2017-12-13 Thread drone4four
Hi fellow Djangoistas: 

I'm back.  

Thank you Atonis for your help.  I suppose I can leave the WYSIWYG editor 
static files for later when I have alittle more experience.  For now 
though: how can I enable HTML markup to parse like it should?  The box 
where users on my Django website make a blog post, they can attach images, 
apply a timestamp but the content is just plain text.  How do I make it so 
that when I user for example enters this:

Lorem Ipsum
Hello and welcome to my first blog post

...that it posts and parses not as plain text but with the heading showing 
with a slightly larger font size than the rest and the first sentence is 
bolded?

Thanks again.

-Drone4four  

On Sunday, November 19, 2017 at 5:31:37 AM UTC-5, Antonis Christofides 
wrote:
>
> Hello,
>
> First of all: If you are just starting to learn, and because the amount 
> you have to learn can be overwhelming, I'd suggest to not care about the 
> wysiwyg editor at this stage. Pretend that your users can enter HTML in the 
> field, and do all the rest. After you get some understanding of static 
> files, only then come back to this issue.
>
> But to (prematurely) answer your question, if you have DEBUG=True and 
> running django with manage.py runserver, you shouldn't need to care about 
> STATIC_ROOT and STATIC_URL and collectstatic. Just forget about them. When 
> the time comes to deploy your application and turn DEBUG off, then you will 
> need to understand how static files work in production 
> <https://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/>
> .
>
> Regards,
>
> Antonis
>
> Antonis Christofideshttp://djangodeployment.com
>
>
> On 2017-11-19 01:38, drone4four wrote:
>
> The official Django docs specify that STATIC_ROOT is indicated in 
> settings.py at the STATIC_URL variable (which is near the bottom).  The 
> official Django docs says:
>
> Configure your web server to serve the files in STATIC_ROOT 
>> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_ROOT>
>>  
>> under the URL STATIC_URL 
>> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_URL>.
>>  
>>  
>
> (link 
> <https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/>)
>
> I’m not running Apache. My Django serving is running locally. The absolute 
> path in my file tree to my Django root directory is:
>
>
> /home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/
>
> Inside dobbs_portal_blog is where I placed the static folder. Therefore, 
> the line in my settings.py where I declare the variable, I changed from the 
> default:
>
> *STATIC_URL = '/static/'* 
>
> to: 
>
> *STATIC_URL = 
> '/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/static/'*
>
> That is my best guess at attempting resolve the “pretty obvious” error 
> message:
>
> You're using the staticfiles app without having set the STATIC_ROOT 
>> setting to a filesystem path.
>
>
> Yet I am still doing something wrong because invoking python3 
> dobbs_portal_blog/manage.py collectstatic, I still get the same message:
>
> $ python3 dobbs_portal_blog/manage.py collectstatic
>> You have requested to collect static files at the destination location 
>> as specified in your settings.
>> This will overwrite existing files! Are you sure you want to do this?
>> Type 'yes' to continue, or 'no' to cancel: yes Traceback (most recent 
>> call last):  File "dobbs_portal_blog/manage.py", line 22, in 
>> execute_from_command_line(sys.argv) 
>>  File 
>> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
>>  
>> line 364, in execute_from_command_lineutility.execute()  File 
>> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
>>  
>> line 356, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv) 
>>  File 
>> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
>>  
>> line 283, in run_from_argvself.execute(*args, **cmd_options)  File 
>> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
>>  
>> line 330, in executeoutput = self.handle(*args, **options)  File 
>> "/home/gnull/Dropbox/TECH/python/2017/django-e

Re: Django field model for HTML parser?

2017-11-18 Thread drone4four


The official Django docs specify that STATIC_ROOT is indicated in 
settings.py at the STATIC_URL variable (which is near the bottom).  The 
official Django docs says:


Configure your web server to serve the files in STATIC_ROOT 
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_ROOT>
>  
> under the URL STATIC_URL 
> <https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-STATIC_URL>.
>  
>  

(link 
<https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/>)

I’m not running Apache. My Django serving is running locally. The absolute 
path in my file tree to my Django root directory is:

/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/

Inside dobbs_portal_blog is where I placed the static folder. Therefore, 
the line in my settings.py where I declare the variable, I changed from the 
default:


*STATIC_URL = '/static/'* 

to: 


*STATIC_URL = 
'/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/dobbs_portal_blog/static/'*


That is my best guess at attempting resolve the “pretty obvious” error 
message:


You're using the staticfiles app without having set the STATIC_ROOT setting 
> to a filesystem path.


Yet I am still doing something wrong because invoking python3 
dobbs_portal_blog/manage.py collectstatic, I still get the same message:

$ python3 dobbs_portal_blog/manage.py collectstatic
> You have requested to collect static files at the destination
> location as specified in your settings.
> This will overwrite existing files!
> Are you sure you want to do this?
> Type 'yes' to continue, or 'no' to cancel: yes
> Traceback (most recent call last):
>  File "dobbs_portal_blog/manage.py", line 22, in 
>execute_from_command_line(sys.argv)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 364, in execute_from_command_line
>utility.execute()
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 356, in execute
>self.fetch_command(subcommand).run_from_argv(self.argv)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 283, in run_from_argv
>self.execute(*args, **cmd_options)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 330, in execute
>output = self.handle(*args, **options)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
>  
> line 199, in handle
>collected = self.collect()
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
>  
> line 124, in collect
>handler(path, prefixed_path, storage)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
>  
> line 354, in copy_file
>if not self.delete_file(path, prefixed_path, source_storage):
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
>  
> line 260, in delete_file
>if self.storage.exists(prefixed_path):
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/files/storage.py",
>  
> line 392, in exists
>return os.path.exists(self.path(name))
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
>  
> line 50, in path
>raise ImproperlyConfigured("You're using the staticfiles app "
> django.core.exceptions.ImproperlyConfigured: You're using the staticfiles 
> app without having set the STATIC_ROOT setting to a filesystem path.


Thanks for your attention and thank you Simon for your patience.


On Saturday, November 18, 2017 at 3:54:11 PM UTC-5, Simon Connah wrote:
>
> The error message is pretty obvious.
>
> "You're using the staticfiles app without having

Re: Django field model for HTML parser?

2017-11-18 Thread drone4four


Thank you, Jason.  The WYSIWYG editor like ckeditor is precisely what I am 
looking for.  

I have set out to run ckeditor.  I am following along with the instructions 
on how to install it 
<https://django-ckeditor.readthedocs.io/en/latest/#installation>.

Inside my virtual environment I invoke pip install django-ckeditor.

Then I add ckeditor to INSTALLED_APPS in settings.py.

But then my shell is telling me that I have improperly configured static 
root in the files app even though my settings.py does include a line: 
STATIC_URL = '/static/'


The installation doc linked to above does refer to the official Django doc 
on how to manage static files 
<https://docs.djangoproject.com/en/dev/howto/static-files/>, which I find 
to be helpful but isn’t really very applicable to my particular situation 
because I do not have any image files that I am working with in my case at 
this point.

When I run python3 dobbs_portal_blog/manage.py collectstatic, I get this 
error:

$ python3 dobbs_portal_blog/manage.py collectstatic

You have requested to collect static files at the destination

location as specified in your settings.

This will overwrite existing files!

Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

Traceback (most recent call last):

 File "dobbs_portal_blog/manage.py", line 22, in 

   execute_from_command_line(sys.argv)

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
 
line 364, in execute_from_command_line

   utility.execute()

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/__init__.py",
 
line 356, in execute

   self.fetch_command(subcommand).run_from_argv(self.argv)

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
 
line 283, in run_from_argv

   self.execute(*args, **cmd_options)

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/management/base.py",
 
line 330, in execute

   output = self.handle(*args, **options)

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
 
line 199, in handle

   collected = self.collect()

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
 
line 124, in collect

   handler(path, prefixed_path, storage)

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
 
line 354, in copy_file

   if not self.delete_file(path, prefixed_path, source_storage):

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
 
line 260, in delete_file

   if self.storage.exists(prefixed_path):

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/core/files/storage.py",
 
line 392, in exists

   return os.path.exists(self.path(name))

 File 
"/home/gnull/Dropbox/TECH/python/2017/django-experiment-with-nick/subgenius-blog-env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
 
line 50, in path

   raise ImproperlyConfigured("You're using the staticfiles app "

django.core.exceptions.ImproperlyConfigured: You're using the staticfiles 
app without having set the STATIC_ROOT setting to a filesystem path.

(subgenius-blog-env) gnull at gnosis in 

$


On Saturday, November 18, 2017 at 7:46:21 AM UTC-5, Jason wrote:
>
> What you're trying to look for is a WYSIWYG editor (What You See Is What 
> You Get), and there are a number of third party packages you can look at 
> https://djangopackages.org/grids/g/wysiwyg/
>
> ckeditor is one of the largest and most popular such projects, and has 
> integration with django via 
> https://github.com/django-ckeditor/django-ckeditor
>
>
> On Friday, November 17, 2017 at 9:21:57 PM UTC-5, drone4four wrote:
>>
>> I didn’t do a very good job explaining.  Let me try again.
>>
>> If you take a look at this image of Blogger, the red arrow points to the 
>> formatting bar <https://imgur.com/LpksoNE>.  The formatting is a helpful 
>> feature in Blogger which allows blog posters to add an essay worth of 
>> cont

Re: Django field model for HTML parser?

2017-11-17 Thread drone4four


I didn’t do a very good job explaining.  Let me try again.

If you take a look at this image of Blogger, the red arrow points to the 
formatting bar <https://imgur.com/LpksoNE>.  The formatting is a helpful 
feature in Blogger which allows blog posters to add an essay worth of 
content, and then alter the appearance of the Lorem Ipsum essay content 
with bold, italics, underline and a few dozen other buttons and options.

Then when you click the HTML button <https://imgur.com/4SD6abe> in the 
Blogger dashboard, it shows you the same Lorem Ipsum content, but just the 
raw HTML source.

My Django admin panel when creating a new blog post just accepts plain 
text.  No HTML markup formatting.  Here is a pic of my Django dashboard with 
a red arrow pointing to where I am hoping to add an HTML formatting bar 
<https://imgur.com/Pkcva1s>. Or does Django not have an HTML formatting 
menu feature helping blog contributors to format their content?  I can’t 
find it in the model field type / option doc that I linked to in my 
original post.

Thank you.

On Wednesday, November 15, 2017 at 10:41:31 PM UTC-5, Amitesh Sahay wrote:
>
> The HTML file in Django is parsed through views.py if that is what you are 
> looking for. For Italics  tag should work. For strong text, you may use 
>  tag. I hope that I have understood your question correctly.
>
> Hello,
>
> Regards,
> Amitesh Sahay
>
> primary :: *91-907 529 6235*
>
>
> On Thursday 16 November 2017, 6:51:03 AM IST, drone4four <
> drone...@gmail.com > wrote: 
>
>
> The contents of my models.py looks like this:
>
> from django.db import models
>
>
> # Create your models here.
> class Post(models.Model):
> title = models.CharField(max_length=256)
> pub_date = models.DateTimeField()
> image = models.ImageField(upload_to='media/')
> body = models.TextField()
>
>
> def __str__(self):
> return self.title
>
>
> def pub_date_pretty(self):
> return self.pub_date.strftime('%A %d %B %Y @ %-I:%M:%S %p')
>
>
> def summary(self):
> return self.body[:350]
>
> Lines 5 through 8 initiate the model class variables for my blog 
> dashboard. My dashboard looks like this <https://imgur.com/a/HTffL>. 
> There is a title, pub date, image and body. The Udemy instructor suggests 
> consulting the official Django doc for field types/options 
> <https://docs.djangoproject.com/en/1.11/ref/models/fields/>. I’m not sure 
> I really understand most of it. There is just so much information there. My 
> question for all of you: Which field option or field type initiates an HTML 
> parser for body text? I mean, when I go to to create a new blog post, how 
> do I create rich text with HTML formatting buttons like bold, underline and 
> italics? It’s not really the buttons I care about. I just want my HTML tags 
> to parse. Take note of the HTML tags I’ve circled in red here 
> <https://imgur.com/a/wV4qs>. How do I get the h5, hr and em to parse? Is 
> there a field option/type for this? I don’t see it in the models fields doc.
>
> Thanks for your attention.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/d387add4-9859-4410-a882-cf98ee3a6278%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/d387add4-9859-4410-a882-cf98ee3a6278%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7d066e4-0cdf-46af-aa56-47a211611c67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django debug of templates and home.html

2017-11-15 Thread drone4four
Amitesh, here are the contents of my home.html:


> 
>   
> J. R. Dobb's Blog!
> 
> 
> 
> 
>  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css;
>  
> integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
>  
> crossorigin="anonymous">
>   
>   
> 
>   
> 
>   Dobbs' Clearing House
> 
>   
> 
> Hello, world!
> 
> 
> 
>   
> 
> Dobbs' Homepage Test
>  Latest News and Updates
> {% for post in posts.all %}
> {{ post.title }}
> 
> {{ post.pub_date_pretty }}
> 
> 
> 
> {{ post.summary }}
> 
> 
> {% endfor %}


Sorry if I confused you with the lorem ipsum non sense.  Please disregard 
that last post of mine.  

Thanks again,

Drone4four

On Wednesday, November 15, 2017 at 10:35:20 PM UTC-5, Amitesh Sahay wrote:
>
> Hello, 
>
> In the settings.py please give the full path to your appsclass as 
> mentioned in app.py. That should be the standard. 
>
> Please share the HTML code here, then it should be clear for further 
> suggestion.
>
> Regards,
> Amitesh Sahay
>
> primary :: *91-907 529 6235*
>
>
> On Thursday 16 November 2017, 6:47:43 AM IST, drone4four <
> drone...@gmail.com > wrote: 
>
>
> I am having fun trying to initiate a django project with some apps. I am 
> taking an awesome course on udemy called, The Ultimate Beginner's Guide to 
> Django. I was able to follow along and I have a basic blog up and running. 
> Now I am back tracking a little by starting over, this time using a 
> supplementary Django cheat sheet. I encountered a number of issues and 
> resolved them but now I find myself stuck. 
>
> When I try navigating to my new homepage, Django provides me with this 
> debug traceback <https://pastebin.com/QqXhgVM3>. Django is telling me 
> here that the templates directory doesn’t exist, when it clearly does. Here 
> is a screenshot of Atom <https://imgur.com/a/mth7B> so you can see my 
> project’s file tree. As you can see my directory tree for my project, there 
> is an folder which is called, blogitems. and within the blogitems folder is 
> a sub-folder called, templates, then blogitems again and finally my file, 
> home.html
>
> It’s rather confusing. I don’t like the redundancy and the recursive 
> nature of all the app files and directory names. Maybe this is my problem. 
> Can any of your make sense of my debug output to explain why I am getting 
> the error? Can anyone please provide some clarity here?
>
> Here is the cheat sheet:
>
> *Creating a Django App*
>
> 1. Open terminal and navigate to django project folder (where manage.py 
> exists)
> 2. django-admin startapp [app name] # use pluralised names, e.g. posts
> 3. Navigate to new app folder.
> 4. Create new subfolder called “templates”
> 5. Navigate to new templates folder.
> 6. Create new subfolder called same name as your app (e.g. posts)
> 7. Go back to project folder
> 9. Open project urls.py and add “from [appname] import views”. Then add 
> url path for new view.
>  e.g. url(r’^$’, views.home, name=‘home’)
> 10.Open views.py and add:
> def home(request):
> return render(request, ‘posts/home.html’)
>
>
> 11. Navigate to projectfolder\appfolder\templates\appfolder
> 12.  Create new file ‘home.html’
> 13.  Go to project folder and open settings.py. Scroll down to 
> INSTALLED_APPs and add ‘appname’, to the end of the list of apps.
>
>
> It's this last step where I encounter the error. 
>
> Here are the contents of urls.py:
> from django.conf.urls import url
> from django.contrib import admin
> from blogitems import views
>
> urlpatterns = [
> #initialization admin interface:
> url(r'^admin/', admin.site.urls),
> url(r’^$’, views.home, name=‘home’),
> ]
>
>
>
> I added the app into the settings.py:
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'blogitems',
> ]
>
> Is there any other information I could provide?
>
> Thanks for your attention.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view

Re: Django debug of templates and home.html

2017-11-15 Thread drone4four
Hello Amitesh.  Thank you for your reply.

The contents of my apps.py reads:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig


class BlogitemsConfig(AppConfig):
name = 'blogitems'

There is no instance of 'BlogitemsConfig' or 'AppConfig' inside 
settings.py. Could that be my issue?  

Here is some sample HTML that I am trying to experiment with:

...at Dundas Square in Toronto.  Here is my report:
>
> abstract Sed a lorem est. Maecenas faucibus sollicitudin velit, 
> sit amet lacinia orci tempor eu. Pellentesque habitant morbi tristique 
> senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante 
> ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In 
> placerat leo vel nisl venenatis, ut tincidunt nulla placerat. 
> Aliquam vehicula, justo nec lobortis dignissim, sapien ex rhoncus mi, 
> ut pretium tortor elit eget sapien. Pellentesque at enim dignissim, 
> imperdiet urna et, molestie massa. Nam posuere, tortor ac dignissim 
> scelerisque, tellus est varius enim, egestas vehicula felis augue ac nisl. 
> Nulla facilisi. Mauris vitae turpis at tortor pulvinar egestas eu vel 
> risus. Duis tincidunt rhoncus aliquet. Duis hendrerit posuere diam, sed 
> eleifend neque vehicula quis. Nulla molestie est est, quis varius metus 
> viverra sit amet. 
> 
>
> Sed et ipsum porta turpis consequat efficitur. Suspendisse congue, 
> tellus ac aliquam molestie, tellus tortor fringilla dolor, sit amet 
> faucibus risus lacus sed nunc. Ut enim leo, viverra ut orci a, dignissim 
> fermentum diam. Phasellus dignissim auguet est dignissim, vel euismod leo 
> molestie. Fusce erat massa, cursus eget nibh eget, rhoncus fermentum enim. 
> Praesent interdum aliquam volutpat. Aenean ut iaculis augue. Sed metus 
> tortor, dignissim sit amet feugiat nec, lacinia vitae nisi. Sed eu 
> facilisis augue. Nulla sagittis, ante nec commodo tincidunt, purus sapien 
> vehicula est, ut vulputate lorem lacus vitae mi. Morbi non nibh pretium, 
> molestie magna ac, auctor ante. Proin quis sapien sed dui feugiat egestas 
> auctor condimentum diam. Pellentesque vulputate lorem massa, non feugiat 
> leo eleifend placerat. Donec semper arcu vitae molestie pretium. 
>
> 
>
>
>
>   Introduction
> Suspendisse ac metus varius, scelerisque dolor a, lacinia sem. Aliquam 
> at enim a dui aliquam condimentum et ut mauris. Cras facilisis tortor sit 
> amet consectetur pellentesque. Nullam eget pellentesque augue, non iaculis 
> mauris. In hac habitasse platea dictumst. Quisque ullamcorper volutpat 
> ornare. Cras ornare vestibulum ornare. 
>
>
>




On Wednesday, November 15, 2017 at 10:35:20 PM UTC-5, Amitesh Sahay wrote:
>
> Hello, 
>
> In the settings.py please give the full path to your appsclass as 
> mentioned in app.py. That should be the standard. 
>
> Please share the HTML code here, then it should be clear for further 
> suggestion.
>
> Regards,
> Amitesh Sahay
>
> primary :: *91-907 529 6235*
>
>
> On Thursday 16 November 2017, 6:47:43 AM IST, drone4four <
> drone...@gmail.com > wrote: 
>
>
> I am having fun trying to initiate a django project with some apps. I am 
> taking an awesome course on udemy called, The Ultimate Beginner's Guide to 
> Django. I was able to follow along and I have a basic blog up and running. 
> Now I am back tracking a little by starting over, this time using a 
> supplementary Django cheat sheet. I encountered a number of issues and 
> resolved them but now I find myself stuck. 
>
> When I try navigating to my new homepage, Django provides me with this 
> debug traceback <https://pastebin.com/QqXhgVM3>. Django is telling me 
> here that the templates directory doesn’t exist, when it clearly does. Here 
> is a screenshot of Atom <https://imgur.com/a/mth7B> so you can see my 
> project’s file tree. As you can see my directory tree for my project, there 
> is an folder which is called, blogitems. and within the blogitems folder is 
> a sub-folder called, templates, then blogitems again and finally my file, 
> home.html
>
> It’s rather confusing. I don’t like the redundancy and the recursive 
> nature of all the app files and directory names. Maybe this is my problem. 
> Can any of your make sense of my debug output to explain why I am getting 
> the error? Can anyone please provide some clarity here?
>
> Here is the cheat sheet:
>
> *Creating a Django App*
>
> 1. Open terminal and navigate to django project folder (where manage.py 
> exists)
> 2. django-admin startapp [app name] # use pluralised names, e.g. posts
> 3. Navigate to new app folder.
> 4. Create new subfolder called “templates”
> 5. Navigate to new templates folder.
> 6. Create

Django field model for HTML parser?

2017-11-15 Thread drone4four
The contents of my models.py looks like this:

from django.db import models


# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=256)
pub_date = models.DateTimeField()
image = models.ImageField(upload_to='media/')
body = models.TextField()


def __str__(self):
return self.title


def pub_date_pretty(self):
return self.pub_date.strftime('%A %d %B %Y @ %-I:%M:%S %p')


def summary(self):
return self.body[:350]

Lines 5 through 8 initiate the model class variables for my blog dashboard. 
My dashboard looks like this . There is a title, 
pub date, image and body. The Udemy instructor suggests consulting the 
official Django doc for field types/options 
. I’m not sure I 
really understand most of it. There is just so much information there. My 
question for all of you: Which field option or field type initiates an HTML 
parser for body text? I mean, when I go to to create a new blog post, how 
do I create rich text with HTML formatting buttons like bold, underline and 
italics? It’s not really the buttons I care about. I just want my HTML tags 
to parse. Take note of the HTML tags I’ve circled in red here 
. How do I get the h5, hr and em to parse? Is 
there a field option/type for this? I don’t see it in the models fields doc.

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d387add4-9859-4410-a882-cf98ee3a6278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django debug of templates and home.html

2017-11-15 Thread drone4four
I am having fun trying to initiate a django project with some apps. I am 
taking an awesome course on udemy called, The Ultimate Beginner's Guide to 
Django. I was able to follow along and I have a basic blog up and running. 
Now I am back tracking a little by starting over, this time using a 
supplementary Django cheat sheet. I encountered a number of issues and 
resolved them but now I find myself stuck. 

When I try navigating to my new homepage, Django provides me with this 
debug traceback . Django is telling me here 
that the templates directory doesn’t exist, when it clearly does. Here is a 
screenshot of Atom  so you can see my project’s 
file tree. As you can see my directory tree for my project, there is an 
folder which is called, blogitems. and within the blogitems folder is a 
sub-folder called, templates, then blogitems again and finally my file, 
home.html

It’s rather confusing. I don’t like the redundancy and the recursive nature 
of all the app files and directory names. Maybe this is my problem. Can any 
of your make sense of my debug output to explain why I am getting the 
error? Can anyone please provide some clarity here?

Here is the cheat sheet:

*Creating a Django App*

1. Open terminal and navigate to django project folder (where manage.py 
> exists)
> 2. django-admin startapp [app name] # use pluralised names, e.g. posts
> 3. Navigate to new app folder.
> 4. Create new subfolder called “templates”
> 5. Navigate to new templates folder.
> 6. Create new subfolder called same name as your app (e.g. posts)
> 7. Go back to project folder
> 9. Open project urls.py and add “from [appname] import views”. Then add 
> url path for new view.
>  e.g. url(r’^$’, views.home, name=‘home’)
> 10.Open views.py and add:
> def home(request):
> return render(request, ‘posts/home.html’)
>
>
> 11. Navigate to projectfolder\appfolder\templates\appfolder
> 12.  Create new file ‘home.html’
> 13.  Go to project folder and open settings.py. Scroll down to 
> INSTALLED_APPs and add ‘appname’, to the end of the list of apps.


It's this last step where I encounter the error. 

Here are the contents of urls.py:
from django.conf.urls import url
from django.contrib import admin
from blogitems import views

urlpatterns = [
#initialization admin interface:
url(r'^admin/', admin.site.urls),
url(r’^$’, views.home, name=‘home’),
]



I added the app into the settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blogitems',
]

Is there any other information I could provide?

Thanks for your attention.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/770a99c0-3824-4e73-914e-f380fd5f48f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Setting up Django for the first time, urls.py and settings.py

2017-10-01 Thread drone4four


I’m playing with Django for the first time.  I am using a guide called, “Python 
from Scratch - Creating a Dynamic Website 
”  by [b]Tuts+ Code[/b] from 
YouTube.  It’s kinda old.  It was first posted in November 2011 and Django 
has evolved considerably.  I’ve had to try different commands, like 
‘syncdb’ is no longer used.  Now it’s ‘migrate’. Yes, Tuts+ Code is over 6 
years old, but it’s the best tutorial in terms of explanations and teaching 
style. Anyways.

I’m getting an error saying there is something wrong with my settings.py:

> $ python ../manage.py runserver
> Performing system checks...
> Unhandled exception in thread started by  0x7fe4876e76e0>
> Traceback (most recent call last):
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/autoreload.py", 
> line 228, in wrapper
>fn(*args, **kwargs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py",
>  
> line 125, in inner_run
>self.check(display_num_errors=True)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 359, in check
>include_deployment_checks=include_deployment_checks,
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 346, in _run_checks
>return checks.run_checks(**kwargs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/registry.py",
>  
> line 81, in run_checks
>new_errors = check(app_configs=app_configs)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py", 
> line 16, in check_url_config
>return check_resolver(resolver)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/core/checks/urls.py", 
> line 26, in check_resolver
>return check_method()
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 254, in check
>for pattern in self.url_patterns:
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py", 
> line 35, in __get__
>res = instance.__dict__[self.name] = self.func(instance)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 405, in url_patterns
>patterns = getattr(self.urlconf_module, "urlpatterns", 
> self.urlconf_module)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/utils/functional.py", 
> line 35, in __get__
>res = instance.__dict__[self.name] = self.func(instance)
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/urls/resolvers.py", 
> line 398, in urlconf_module
>return import_module(self.urlconf_name)
>  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
>__import__(name)
>  File 
> "/home/gnull/Dropbox/TECH/python/2017/beginning-Django/G_Thomas/G_Thomas/urls.py",
>  
> line 21, in 
>url(r'^$', 'blog.views.home', name='home')
>  File 
> "/home/gnull/.local/lib/python2.7/site-packages/django/conf/urls/__init__.py",
>  
> line 85, in url
>raise TypeError('view must be a callable or a list/tuple in the case of 
> include().')
> TypeError: view must be a callable or a list/tuple in the case of 
> include().


Those last couple of lines in this error message are instructive. I’m not 
sure about the case of include() in urls.py but my url declaration indeed 
is a tuple.  Why is my shell telling me there is something wrong with my 
tuple when it should be a tuple?  I also swapped out the parentheses with 
square brackets to see if it would take a list as it says it can.  Either 
way, same error.

Here are the contents of my urls.py:

from django.conf.urls import *
> from django.contrib import admin
> admin.autodiscover()
> urlpatterns = ['',
> # url(r'^admin/', admin.site.urls),
> url(r'^$', 'blog.views.home', name='home')
> ]


Take note of the square brackets and lack of the patterns function (as 
compared to the presence of the function in the code from the teacher 
below). Also commented out above is the default urlpattern that came with 
Django 1.11.  

So the urlpattern in Tuts+ Code’s actually looks like this:

from django.conf.urls.defaults import patterns, include, url
> from django.contrib import admin
> urlpatterns = patterns (‘’,
> url(r'^$', ‘FirstBlog.views.home’, name='home'),
> )


Addressing a related issue with importing the name pattern in urls.py for 
Django, some folks over on stackoverflow describe their Djanog urls.py 
 
configuration file use a simple variable declaration for urlpatterns and 
don’t bother with the function patterns() the way the YouTuber explains 
that it should look like.  Like, the YouTuber uses: ‘*urlpatterns = 
patterns( ... )*’ whereas the stackoverflow people set it as: ‘*urlpatterns 
= [ ‘’, ...]'*.  

I get the sense that I am slightly off in my understanding of the issue.