API Django

2018-10-21 Thread Phako Perez
Hi all,

i'm really new on Django, trying to create an RESTful API, and getting this
error:

curl -i -U Elly:Elly -H "Content-Type: application/json" -X GET
http://192.168.100.22:8000/schedule/3/


HTTP/1.1 403 Forbidden

Date: Mon, 22 Oct 2018 05:44:40 GMT

Server: WSGIServer/0.2 CPython/3.6.3

Content-Type: application/json

Vary: Accept, Cookie

Allow: OPTIONS

X-Frame-Options: SAMEORIGIN

Content-Length: 58


{"detail":"Authentication credentials were not provided."}

on my settings.py added below

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.permissions.IsAuthenticated'
),
}


views.py

from schedule.models import Schedule
from users.models import User
from rest_framework import exceptions
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication,
BasicAuthentication
from rest_framework.permissions import IsAuthenticated

from schedule.serializers import ScheduleSerializer


class ScheduleList(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)

def authenticate(self, request):
username = request.META.get('X_USERNAME')
if not username:
return None
try:
user = User.objects.get(username=username)
except:
raise exceptions.AuthenticationFailed('No such user')
return Response(user, None)

queryset = 
Schedule.objects.all().filter(user=User.objects.all().filter(id=5)[0])
serializer_class = ScheduleSerializer

def perform_create(self, serializer):
serializer.save(user=self.request.user)


class ScheduleDetail(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)

def authenticate(self, request):
username = request.META.get('X_USERNAME')
if not username:
return None
try:
user = User.objects.get(username=username)
except:
raise exceptions.AuthenticationFailed('No such user')
return Response(user, None)

serializer_class = ScheduleSerializer

def get_queryset(self):
return 
Schedule.objects.all().filter(user=User.objects.all().filter(id=5)[0])


thanks in advance

-- 
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/CAF%3Duzp30Enf%2BE7mWHXG6t2ZAj5YKc11oQkg4HSQOPaHTOO0QsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template Issues

2018-10-21 Thread Siddharth Tamang
Are you getting any exception? Share with us the error that you are seeing

On Mon, Oct 22, 2018 at 12:18 AM vineeth sagar 
wrote:

> Do you mean bootstrap? STL doesn't care about that and it's not clear what
> you mean. Can you share the code so that we can help you.
>
> On Oct 22, 2018 12:14 AM, "Dennis Alabi"  wrote:
>
>> i am Building Django 2.0 Web Applications, template is not rendering with
>> boottrap3.
>>
>> --
>> 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/47edff6d-c85e-4a54-af3e-67736f2d72fe%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/CAMMZq8MU_kmUgC5TnDgYWenD8K%2BZed9RJ-Q7R3jvpGhq_qj-Lw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thank you
Siddharth Tamang
AWS Certified Solutions Architect - Associate

-- 
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/CADBOudv5VLU6Dze5bYPtKHRoRx8w%2Bgo%2BGUBH0SGnjJeKTTqQVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template Issues

2018-10-21 Thread vineeth sagar
Do you mean bootstrap? STL doesn't care about that and it's not clear what
you mean. Can you share the code so that we can help you.

On Oct 22, 2018 12:14 AM, "Dennis Alabi"  wrote:

> i am Building Django 2.0 Web Applications, template is not rendering with
> boottrap3.
>
> --
> 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/47edff6d-c85e-4a54-af3e-67736f2d72fe%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/CAMMZq8MU_kmUgC5TnDgYWenD8K%2BZed9RJ-Q7R3jvpGhq_qj-Lw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Template Issues

2018-10-21 Thread Dennis Alabi
i am Building Django 2.0 Web Applications, template is not rendering with 
boottrap3.

-- 
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/47edff6d-c85e-4a54-af3e-67736f2d72fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [channels] 2.1.4 - Removing Javascript library entirely

2018-10-21 Thread kradem
Ok, thank you very much for your answer!

Dana nedjelja, 21. listopada 2018. u 18:47:14 UTC+2, korisnik Andrew Godwin 
napisao je:
>
> That's about right - you should ship and maintain the file yourself now.
>
> Andrew
>
> On Sun, 21 Oct 2018, 09:04 kradem, > wrote:
>
>> Hi everyone!
>>
>> The subject is related to 
>> https://github.com/django/channels/commit/2a9d764ad03927581aa2bfcadccc3e953949cb98
>>
>> > It was very unmaintained, and having it in here sends the wrong message 
>> about it being useful and reliable.
>>
>> I used to include the javascript in my templates with:
>>
>> 
>>
>> I suppose the only change I should do now is to include the javascript 
>> file from the 2.1.3 channels version in my project static folder and 
>> reference it with (if js is the folder for my project's javascript)::
>>
>> 
>>
>> Am I missing something else here?
>>
>> -- 
>> 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/e5a5eca8-54f1-49f8-9159-f7b7c4de847e%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/7bc0b6e4-420b-4b2c-9d9f-f63d3d981693%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can I implement built in signals, for my app?

2018-10-21 Thread Joel Mathew
How to implement built in signals, for my app?

I have a project myappointments, with two apps appointments and clinic in it.

Objective:
When a user logins, details should be entered in the database.

appointments/models.py:

class Event(models.Model):
id=models.AutoField(primary_key=True, unique=True)
type=models.CharField(max_length=60)
description = models.CharField(max_length=150)
time = models.DateTimeField(default=timezone.now)

appointments/__init__.py:

default_app_config = 'appointments.apps.AppointmentsConfig'

appointments/apps.py:

from django.apps import AppConfig
class AppointmentsConfig(AppConfig):
name = 'appointments'
def ready(self):
import appointments.signals  # noqa

appointments/signals.py:

from django.contrib.auth.signals import user_logged_in
from django.dispatch import receiver
def record_loggedin(sender, user, request, **kwargs):
  ev = Event(type="Login", description = 'User logged in:
{}'.format(request.user.id))
  ev.save()
  print("User has logged in. Saved event to DB.")
  user_logged_in.connect(record_loggedin)

What other modifications do I need to do this?

- Joel G Mathew

-- 
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/CAA%3Diw_8ViZgvx8ugBaC0_1uqaOUkCMLmS7adMCoQUmOZL9nJfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [channels] 2.1.4 - Removing Javascript library entirely

2018-10-21 Thread Andrew Godwin
That's about right - you should ship and maintain the file yourself now.

Andrew

On Sun, 21 Oct 2018, 09:04 kradem,  wrote:

> Hi everyone!
>
> The subject is related to
> https://github.com/django/channels/commit/2a9d764ad03927581aa2bfcadccc3e953949cb98
>
> > It was very unmaintained, and having it in here sends the wrong message
> about it being useful and reliable.
>
> I used to include the javascript in my templates with:
>
> 
>
> I suppose the only change I should do now is to include the javascript
> file from the 2.1.3 channels version in my project static folder and
> reference it with (if js is the folder for my project's javascript)::
>
> 
>
> Am I missing something else here?
>
> --
> 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/e5a5eca8-54f1-49f8-9159-f7b7c4de847e%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/CAFwN1uoZkwbKwV6kX12hWGrE3VtyTM1tb2V-7tti38qdn4vgqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[channels] 2.1.4 - Removing Javascript library entirely

2018-10-21 Thread kradem
Hi everyone!

The subject is related to 
https://github.com/django/channels/commit/2a9d764ad03927581aa2bfcadccc3e953949cb98

> It was very unmaintained, and having it in here sends the wrong message 
about it being useful and reliable.

I used to include the javascript in my templates with:



I suppose the only change I should do now is to include the javascript file 
from the 2.1.3 channels version in my project static folder and reference 
it with (if js is the folder for my project's javascript)::



Am I missing something else here?

-- 
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/e5a5eca8-54f1-49f8-9159-f7b7c4de847e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: generate username and password

2018-10-21 Thread fatoubinetou196
Okae! pourquoi c'est mauvais pour le mot de passe?

Le vendredi 19 octobre 2018 01:24:54 UTC, fatoubi...@gmail.com a écrit :
>
> Bonjour! Je voudrais lorsqu'un utilisateur s'inscrit avec ses informations 
> personnelles puis soumet le formulaire, je lui génère un nom d'utilisateur 
> et un mot de passe qu'on envoie dans son mail fourni. 
>

-- 
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/752331fd-8688-4f89-898b-869c532667d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using the URLconf defined in polls.urls, Django tried these URL patterns, in this order

2018-10-21 Thread Motaz Hejaze
first , no spaces are allowed in URLS
as  Manjunath said
replace path(' ', views.index, name='index') with path('', views.index,
name='index') in your polls/urls.py and check the result.

second , run the server
python manage.py runserver

third check the url
go to http://127.0.0.1:8000/polls

On Sun, Oct 21, 2018 at 1:56 PM Manjunath  wrote:

> I think you have a space in your url path.
>
> replace path(' ', views.index, name='index') with path('', views.index,
> name='index') in your polls/urls.py and check the result.
>
> On Friday, October 19, 2018 at 4:59:10 PM UTC+5:30, Bugs Bunny wrote:
>>
>> Greetings django team, I'm a newbie with this framework but I have
>> experience with python, I did the first tutorial and it throws me a 404
>> error, I saw that in the previous versions we used a r'formated 'string and
>> indicated the beginning ^ and the end $ but in version 2.1 is no longer
>> used, check and I do not know where the error comes from, I will leave some
>> captures, the IRC room is down I hope answers from this wonderful community
>>
>> tuto/urls.py
>>  from django.contrib import admin
>>  from django.urls import include, path
>>
>>  urlpatterns = [
>>  path('polls/', include('polls.urls')),
>>  path('admin/', admin.site.urls),
>>  ]
>>
>>
>>
>>
>>
>> polls/urls.py
>> from django.urls import path
>> from . import views
>>
>> urlpatterns = [
>>  path(' ', views.index, name='index'),
>>  ]
>>
>> polls/views.py
>> from django.shortcuts import render
>> from django.http import HttpResponse as HR
>> # Create your views here.
>>
>> def index(request):
>>return HR("hola estas en el index de polls")
>>
>>
>> mi internet its very laggy
>>
> --
> 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/8b8d005c-e2c1-4399-9bd8-9deb1cdea9f8%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/CAHV4E-cjH_Zc645Hj13201Z8Fme%2BBevfqA5oie5Gnz9ZN%3DGt%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test error

2018-10-21 Thread Motaz Hejaze
f'{}' is not supported

On Sun, Oct 21, 2018 at 2:29 PM Joel  wrote:

> What is your version of python? f strings were introduced in 3.6
>
> On Sun, 21 Oct, 2018, 9:54 AM Tim Vogt (Tim Vogt), 
> wrote:
>
>> I try to make a test with has an error
>> any suggestions?
>> tim
>>
>>
>> expected_author = f'{post.author}
>> ^
>> SyntaxError: EOL while scanning string literal
>>
>>
>> --
>> Ran 1 test in 0.000s
>>
>> FAILED (errors=1)
>> Destroying test database for alias 'default'...
>> MacBook-Pro-15-Officerebel:blogapi timvogt$
>>
>>
>> from django.test import TestCase
>> from django.contrib.auth.models import User
>>
>> from .models import Post
>>
>> class BlogTests(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> #Create a user
>> testuser1 = User.objects.create_user(
>> username='testuser1', password='abc123')
>> testuser1.save()
>>
>> # Create a blog post
>> test_post = Post.objects.create(
>> author=testuser1, title='Blog title', body='Body content...')
>> test_post.save()
>>
>> def test_blog_content(self):
>> post = Post.objects.get(id=1)
>> expected_author = f'{post.author}'
>> expected_title = f'{post.title}'
>> expected_body = f'{post.body}'
>> self.assertEquals(expected_author, 'testuser1')
>> self.assertEquals(expected_title,'Blog title')
>> self.assertEquals(expected_body, 'Body content ...')
>>
>> --
>> 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/FCBEF0A0-EDB1-4842-BB4E-42249F3F48EB%40gmail.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/CAA%3Diw_8VU9J9QGUz_LNGjBRCQSGo0rpJ1FTtY5H00U_Di_7oiw%40mail.gmail.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/CAHV4E-d4qHggazeGzrZJWdf1_Z766SoiJhqXDwizP5Vuox0nVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test error

2018-10-21 Thread Joel
What is your version of python? f strings were introduced in 3.6

On Sun, 21 Oct, 2018, 9:54 AM Tim Vogt (Tim Vogt), 
wrote:

> I try to make a test with has an error
> any suggestions?
> tim
>
>
> expected_author = f'{post.author}
> ^
> SyntaxError: EOL while scanning string literal
>
>
> --
> Ran 1 test in 0.000s
>
> FAILED (errors=1)
> Destroying test database for alias 'default'...
> MacBook-Pro-15-Officerebel:blogapi timvogt$
>
>
> from django.test import TestCase
> from django.contrib.auth.models import User
>
> from .models import Post
>
> class BlogTests(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> #Create a user
> testuser1 = User.objects.create_user(
> username='testuser1', password='abc123')
> testuser1.save()
>
> # Create a blog post
> test_post = Post.objects.create(
> author=testuser1, title='Blog title', body='Body content...')
> test_post.save()
>
> def test_blog_content(self):
> post = Post.objects.get(id=1)
> expected_author = f'{post.author}'
> expected_title = f'{post.title}'
> expected_body = f'{post.body}'
> self.assertEquals(expected_author, 'testuser1')
> self.assertEquals(expected_title,'Blog title')
> self.assertEquals(expected_body, 'Body content ...')
>
> --
> 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/FCBEF0A0-EDB1-4842-BB4E-42249F3F48EB%40gmail.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/CAA%3Diw_8VU9J9QGUz_LNGjBRCQSGo0rpJ1FTtY5H00U_Di_7oiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test error

2018-10-21 Thread Joel
He's using literal string interpolation.
Read: https://www.python.org/dev/peps/pep-0498/

On Sun, 21 Oct, 2018, 5:49 PM Tommaso Bellini, 
wrote:

> What does mean 'f' ? It is not imported or instanced..what is it?
>
> Il dom 21 ott 2018, 06:24 Tim Vogt (Tim Vogt)  ha
> scritto:
>
>> I try to make a test with has an error
>> any suggestions?
>> tim
>>
>>
>> expected_author = f'{post.author}
>> ^
>> SyntaxError: EOL while scanning string literal
>>
>>
>> --
>> Ran 1 test in 0.000s
>>
>> FAILED (errors=1)
>> Destroying test database for alias 'default'...
>> MacBook-Pro-15-Officerebel:blogapi timvogt$
>>
>>
>> from django.test import TestCase
>> from django.contrib.auth.models import User
>>
>> from .models import Post
>>
>> class BlogTests(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> #Create a user
>> testuser1 = User.objects.create_user(
>> username='testuser1', password='abc123')
>> testuser1.save()
>>
>> # Create a blog post
>> test_post = Post.objects.create(
>> author=testuser1, title='Blog title', body='Body content...')
>> test_post.save()
>>
>> def test_blog_content(self):
>> post = Post.objects.get(id=1)
>> expected_author = f'{post.author}'
>> expected_title = f'{post.title}'
>> expected_body = f'{post.body}'
>> self.assertEquals(expected_author, 'testuser1')
>> self.assertEquals(expected_title,'Blog title')
>> self.assertEquals(expected_body, 'Body content ...')
>>
>> --
>> 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/FCBEF0A0-EDB1-4842-BB4E-42249F3F48EB%40gmail.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/CA%2BhSpwe4fVqaHU6JWvoc6%2B3D9RFF7beXhGzHu%3DaGs0Ez5fggtw%40mail.gmail.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/CAA%3Diw_9rmPgKP-pzk8RB1icpJ8VGzM_XAWVukcn5s2gCF%3DsTiA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: test error

2018-10-21 Thread Tommaso Bellini
What does mean 'f' ? It is not imported or instanced..what is it?

Il dom 21 ott 2018, 06:24 Tim Vogt (Tim Vogt)  ha
scritto:

> I try to make a test with has an error
> any suggestions?
> tim
>
>
> expected_author = f'{post.author}
> ^
> SyntaxError: EOL while scanning string literal
>
>
> --
> Ran 1 test in 0.000s
>
> FAILED (errors=1)
> Destroying test database for alias 'default'...
> MacBook-Pro-15-Officerebel:blogapi timvogt$
>
>
> from django.test import TestCase
> from django.contrib.auth.models import User
>
> from .models import Post
>
> class BlogTests(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> #Create a user
> testuser1 = User.objects.create_user(
> username='testuser1', password='abc123')
> testuser1.save()
>
> # Create a blog post
> test_post = Post.objects.create(
> author=testuser1, title='Blog title', body='Body content...')
> test_post.save()
>
> def test_blog_content(self):
> post = Post.objects.get(id=1)
> expected_author = f'{post.author}'
> expected_title = f'{post.title}'
> expected_body = f'{post.body}'
> self.assertEquals(expected_author, 'testuser1')
> self.assertEquals(expected_title,'Blog title')
> self.assertEquals(expected_body, 'Body content ...')
>
> --
> 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/FCBEF0A0-EDB1-4842-BB4E-42249F3F48EB%40gmail.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/CA%2BhSpwe4fVqaHU6JWvoc6%2B3D9RFF7beXhGzHu%3DaGs0Ez5fggtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using the URLconf defined in polls.urls, Django tried these URL patterns, in this order

2018-10-21 Thread Manjunath
I think you have a space in your url path.

replace path(' ', views.index, name='index') with path('', views.index, 
name='index') in your polls/urls.py and check the result.

On Friday, October 19, 2018 at 4:59:10 PM UTC+5:30, Bugs Bunny wrote:
>
> Greetings django team, I'm a newbie with this framework but I have 
> experience with python, I did the first tutorial and it throws me a 404 
> error, I saw that in the previous versions we used a r'formated 'string and 
> indicated the beginning ^ and the end $ but in version 2.1 is no longer 
> used, check and I do not know where the error comes from, I will leave some 
> captures, the IRC room is down I hope answers from this wonderful community
>
> tuto/urls.py
>  from django.contrib import admin
>  from django.urls import include, path
>
>  urlpatterns = [
>  path('polls/', include('polls.urls')),
>  path('admin/', admin.site.urls),
>  ]
>
>
>
>
>
> polls/urls.py
> from django.urls import path
> from . import views
>
> urlpatterns = [
>  path(' ', views.index, name='index'),
>  ]
>
> polls/views.py
> from django.shortcuts import render
> from django.http import HttpResponse as HR
> # Create your views here.
>
> def index(request):
>return HR("hola estas en el index de polls")
>  
>
> mi internet its very laggy
>

-- 
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/8b8d005c-e2c1-4399-9bd8-9deb1cdea9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.